4bef2b4eaf 2011-04-10 kinaba: #include <iostream> 4bef2b4eaf 2011-04-10 kinaba: #include <sstream> 4bef2b4eaf 2011-04-10 kinaba: #include <iomanip> 4bef2b4eaf 2011-04-10 kinaba: #include <vector> 4bef2b4eaf 2011-04-10 kinaba: #include <string> 4bef2b4eaf 2011-04-10 kinaba: #include <map> 4bef2b4eaf 2011-04-10 kinaba: #include <set> 4bef2b4eaf 2011-04-10 kinaba: #include <algorithm> 4bef2b4eaf 2011-04-10 kinaba: #include <numeric> 4bef2b4eaf 2011-04-10 kinaba: #include <iterator> 4bef2b4eaf 2011-04-10 kinaba: #include <functional> 4bef2b4eaf 2011-04-10 kinaba: #include <complex> 4bef2b4eaf 2011-04-10 kinaba: #include <queue> 4bef2b4eaf 2011-04-10 kinaba: #include <stack> 4bef2b4eaf 2011-04-10 kinaba: #include <cmath> 4bef2b4eaf 2011-04-10 kinaba: #include <cassert> 4bef2b4eaf 2011-04-10 kinaba: #include <cstring> 4bef2b4eaf 2011-04-10 kinaba: using namespace std; 4bef2b4eaf 2011-04-10 kinaba: typedef long long LL; 4bef2b4eaf 2011-04-10 kinaba: typedef complex<double> CMP; 4bef2b4eaf 2011-04-10 kinaba: 4bef2b4eaf 2011-04-10 kinaba: class TheLotteryBothDivs { public: 4bef2b4eaf 2011-04-10 kinaba: double find(vector <string> goodSuffixes) 4bef2b4eaf 2011-04-10 kinaba: { 4bef2b4eaf 2011-04-10 kinaba: sort(goodSuffixes.begin(), goodSuffixes.end()); 4bef2b4eaf 2011-04-10 kinaba: goodSuffixes.erase(unique(goodSuffixes.begin(), goodSuffixes.end()), goodSuffixes.end()); 4bef2b4eaf 2011-04-10 kinaba: double p = 0.0; 4bef2b4eaf 2011-04-10 kinaba: for(int i=0; i<goodSuffixes.size(); ++i) { 4bef2b4eaf 2011-04-10 kinaba: const string& me = goodSuffixes[i]; 4bef2b4eaf 2011-04-10 kinaba: bool use = true; 4bef2b4eaf 2011-04-10 kinaba: for(int k=0; k<goodSuffixes.size(); ++k) 4bef2b4eaf 2011-04-10 kinaba: if( is_proper_suffix(me, goodSuffixes[k]) ) 4bef2b4eaf 2011-04-10 kinaba: use = false; 4bef2b4eaf 2011-04-10 kinaba: if( use ) 4bef2b4eaf 2011-04-10 kinaba: p += pow(0.1, (double)me.size()); 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: return p; 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: bool is_proper_suffix(const string& me, const string& suf) 4bef2b4eaf 2011-04-10 kinaba: { 4bef2b4eaf 2011-04-10 kinaba: if( me.size() <= suf.size() ) 4bef2b4eaf 2011-04-10 kinaba: return false; 4bef2b4eaf 2011-04-10 kinaba: return me.substr(me.size()-suf.size()) == suf; 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: }; 4bef2b4eaf 2011-04-10 kinaba: 4bef2b4eaf 2011-04-10 kinaba: // BEGIN CUT HERE 4bef2b4eaf 2011-04-10 kinaba: #include <ctime> 4bef2b4eaf 2011-04-10 kinaba: double start_time; string timer() 4bef2b4eaf 2011-04-10 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 4bef2b4eaf 2011-04-10 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 4bef2b4eaf 2011-04-10 kinaba: { os << "{ "; 4bef2b4eaf 2011-04-10 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 4bef2b4eaf 2011-04-10 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 4bef2b4eaf 2011-04-10 kinaba: void verify_case(const double& Expected, const double& Received) { 4bef2b4eaf 2011-04-10 kinaba: bool ok = (abs(Expected - Received) < 1e-9); 4bef2b4eaf 2011-04-10 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 4bef2b4eaf 2011-04-10 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 4bef2b4eaf 2011-04-10 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 4bef2b4eaf 2011-04-10 kinaba: #define END verify_case(_, TheLotteryBothDivs().find(goodSuffixes));} 4bef2b4eaf 2011-04-10 kinaba: int main(){ 4bef2b4eaf 2011-04-10 kinaba: 4bef2b4eaf 2011-04-10 kinaba: CASE(0) 4bef2b4eaf 2011-04-10 kinaba: string goodSuffixes_[] = {"4"}; 4bef2b4eaf 2011-04-10 kinaba: vector <string> goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); 4bef2b4eaf 2011-04-10 kinaba: double _ = 0.1; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(1) 4bef2b4eaf 2011-04-10 kinaba: string goodSuffixes_[] = {"4", "7"}; 4bef2b4eaf 2011-04-10 kinaba: vector <string> goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); 4bef2b4eaf 2011-04-10 kinaba: double _ = 0.2; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(2) 4bef2b4eaf 2011-04-10 kinaba: string goodSuffixes_[] = {"47", "47"}; 4bef2b4eaf 2011-04-10 kinaba: vector <string> goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); 4bef2b4eaf 2011-04-10 kinaba: double _ = 0.01; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(3) 4bef2b4eaf 2011-04-10 kinaba: string goodSuffixes_[] = {"47", "58", "4747", "502"}; 4bef2b4eaf 2011-04-10 kinaba: vector <string> goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); 4bef2b4eaf 2011-04-10 kinaba: double _ = 0.021; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(4) 4bef2b4eaf 2011-04-10 kinaba: string goodSuffixes_[] = {"8542861", "1954", "6", "523", "000000000", "5426", "8"}; 4bef2b4eaf 2011-04-10 kinaba: vector <string> goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); 4bef2b4eaf 2011-04-10 kinaba: double _ = 0.201100101; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: /* 4bef2b4eaf 2011-04-10 kinaba: CASE(5) 4bef2b4eaf 2011-04-10 kinaba: string goodSuffixes_[] = ; 4bef2b4eaf 2011-04-10 kinaba: vector <string> goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); 4bef2b4eaf 2011-04-10 kinaba: double _ = ; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(6) 4bef2b4eaf 2011-04-10 kinaba: string goodSuffixes_[] = ; 4bef2b4eaf 2011-04-10 kinaba: vector <string> goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); 4bef2b4eaf 2011-04-10 kinaba: double _ = ; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: */ 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: // END CUT HERE