TopCoderSRM 144 DIV 2 - 550

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;
       }
};


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值