TopCoderSRM 144 DIV 2 - 550
来源:互联网 发布:java连接mysql url 编辑:程序博客网 时间:2024/06/01 22:45
TopCoderSRM 144 DIV 2 - 550
//============================================================================//Name : TopCode.cpp//Author : Oliver//Version ://Copyright : Your copyright notice//Description : Hello World in C++, Ansi-style//============================================================================ #include<iostream>#include<string>#include<vector>#include<cassert>#include<sstream>#include<algorithm>//#include<stdlib.h> usingnamespace std; classTicket{public: Ticket(string name, long long value){ this->name = name; this->value = value; }; string name; long long value;}; booloperator< ( const Ticket& tk1, const Ticket& tk2 ){ if( tk1.value != tk2.value ){ return tk1.value < tk2.value; }else{ return tk1.name < tk2.name; }} classLottery{public: //"INDIGO: 93 8 T F", vector<string>sortByOdds(vector<string> rules){ int len = rules.size(); vector<Ticket> tickets; int choices, blanks; bool isSorted, isUnique; for( auto i = 0; i < len; i++){ string rule = rules[i]; int pos =rule.find_first_of(':'); string name =rule.substr(0, pos); istringstreamiss(rule.substr(pos+2, rule.size())); char ch1, ch2; iss >> choices>> blanks >> ch1 >> ch2; isSorted =(ch1=='T'?true:false); isUnique =(ch2=='T'?true:false); long long value =getPossibilities( choices, blanks, isSorted, isUnique ); tickets.push_back(Ticket(name, value) ); sort( tickets.begin(),tickets.end() ); } vector<string> ret; for( auto it = tickets.begin(); it!= tickets.end(); it++ ){ ret.push_back(it->name); //test cout << it->name<< ": " << it->value << endl; } return ret; } long long getPossibilities( int choices,int blanks, bool isSorted, bool isUnique ){ if( !isSorted && !isUnique){ return power(choices,blanks); }else if( !isSorted &&isUnique ){ return unique(choices,blanks); }else if( isSorted &&isUnique ){ returnsortedUnique(choices, blanks); }else{ returnsortedUnique(choices+blanks-1, blanks); } } long long factorial( int n ){ long long ret = 1; for( auto i = 2; i <= n; i++ ){ ret *= i; } return ret; } long long sortedUnique( int m, int n ){ long long ret = unique(m, n)/(factorial(n)); return ret; } long long unique( int m, int n ){ long long ret = 1; for( auto i = 0; i < n; i++ ){ ret *= m; m--; } return ret; } long long power( int m, int n ){ long long ret = 1; for( auto i = 0; i < n; i++ ){ ret *= m; } return ret; }};
0 0
- TopCoderSRM 144 DIV 2 - 550
- TopCoderSRM 144 DIV 2 - 200
- srm 144 div 2 550
- TopCoder SRM 144 DIV 2
- Top Coder Arena SRM 144 DIV 2 550point
- div-2
- TopCoder SRM676 Div. 2 Problem 550 - BoardEscapeDiv2
- Codeforces Round #144 (Div. 2) (模拟问题)
- 【topcoder】 SRM 144 div 2 200
- Codeforces Round #144 (Div. 2) C. Cycles
- 体验DIV+CSS(2):DIV + CSS 进阶
- Codeforces Round #167 (Div. 2 && Div.1)
- Codeforces Round #185 (Div. 1) && (Div. 2)
- Codeforces Round #166 (Div. 1) && (Div. 2)
- Codeforces Round #292 (Div. 2 Div. 1)
- Codeforces Round #413(Div. 1 + Div. 2)
- div+css (2)
- SRM 458 Div 2
- poj 1200 (字符串hash)
- C# linq to sql
- Ant命令执行build.xml时的参数传递
- 水仙花数
- Codeforces Beta Round #95 (Div. 2) D.Subway
- TopCoderSRM 144 DIV 2 - 550
- c/c++ 实现ping程序
- 第二学期第14周项目1--动物这样叫(要求1)
- vim使用
- 胜利大逃亡(BFS)
- Zigbee协议栈ZStack构架
- 以root登录ubuntu界面
- werwerwer
- 数据持久化(四)之NSUserDefaults