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