1535d63cea 2011-05-28 kinaba: #include <iostream> 1535d63cea 2011-05-28 kinaba: #include <sstream> 1535d63cea 2011-05-28 kinaba: #include <iomanip> 1535d63cea 2011-05-28 kinaba: #include <vector> 1535d63cea 2011-05-28 kinaba: #include <string> 1535d63cea 2011-05-28 kinaba: #include <map> 1535d63cea 2011-05-28 kinaba: #include <set> 1535d63cea 2011-05-28 kinaba: #include <algorithm> 1535d63cea 2011-05-28 kinaba: #include <numeric> 1535d63cea 2011-05-28 kinaba: #include <iterator> 1535d63cea 2011-05-28 kinaba: #include <functional> 1535d63cea 2011-05-28 kinaba: #include <complex> 1535d63cea 2011-05-28 kinaba: #include <queue> 1535d63cea 2011-05-28 kinaba: #include <stack> 1535d63cea 2011-05-28 kinaba: #include <cmath> 1535d63cea 2011-05-28 kinaba: #include <cassert> 1535d63cea 2011-05-28 kinaba: #include <cstring> 1535d63cea 2011-05-28 kinaba: using namespace std; 1535d63cea 2011-05-28 kinaba: typedef long long LL; 1535d63cea 2011-05-28 kinaba: typedef complex<double> CMP; 1535d63cea 2011-05-28 kinaba: 1535d63cea 2011-05-28 kinaba: class TheNumbersWithLuckyLastDigit { public: 1535d63cea 2011-05-28 kinaba: int find(int n) 1535d63cea 2011-05-28 kinaba: { 1535d63cea 2011-05-28 kinaba: int feasible[10][2] = { 1535d63cea 2011-05-28 kinaba: {20, 5}, // 4+4+4+4+4 1535d63cea 2011-05-28 kinaba: {11, 2}, // 4+7 1535d63cea 2011-05-28 kinaba: {12, 3}, // 4+4+4 (4+4+7+7) 1535d63cea 2011-05-28 kinaba: {23, 5}, // 4+4+4+4+7 1535d63cea 2011-05-28 kinaba: { 4, 1}, // 4 (7+7) 1535d63cea 2011-05-28 kinaba: {15, 3}, // 4+4+7 1535d63cea 2011-05-28 kinaba: {16, 4}, // 4+4+4+4 1535d63cea 2011-05-28 kinaba: { 7, 1}, // 7 1535d63cea 2011-05-28 kinaba: { 8, 2}, // 4+4 (4+7+7) 1535d63cea 2011-05-28 kinaba: {19, 4}, // 4+4+4+7 1535d63cea 2011-05-28 kinaba: }; 1535d63cea 2011-05-28 kinaba: if( feasible[n%10][0] <= n ) 1535d63cea 2011-05-28 kinaba: return feasible[n%10][1]; 1535d63cea 2011-05-28 kinaba: return -1; 1535d63cea 2011-05-28 kinaba: } 1535d63cea 2011-05-28 kinaba: }; 1535d63cea 2011-05-28 kinaba: 1535d63cea 2011-05-28 kinaba: // BEGIN CUT HERE 1535d63cea 2011-05-28 kinaba: #include <ctime> 1535d63cea 2011-05-28 kinaba: double start_time; string timer() 1535d63cea 2011-05-28 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 1535d63cea 2011-05-28 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 1535d63cea 2011-05-28 kinaba: { os << "{ "; 1535d63cea 2011-05-28 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 1535d63cea 2011-05-28 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 1535d63cea 2011-05-28 kinaba: void verify_case(const int& Expected, const int& Received) { 1535d63cea 2011-05-28 kinaba: bool ok = (Expected == Received); 1535d63cea 2011-05-28 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 1535d63cea 2011-05-28 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 1535d63cea 2011-05-28 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 1535d63cea 2011-05-28 kinaba: #define END verify_case(_, TheNumbersWithLuckyLastDigit().find(n));} 1535d63cea 2011-05-28 kinaba: int main(){ 1535d63cea 2011-05-28 kinaba: 1535d63cea 2011-05-28 kinaba: CASE(0) 1535d63cea 2011-05-28 kinaba: int n = 99; 1535d63cea 2011-05-28 kinaba: int _ = 4; 1535d63cea 2011-05-28 kinaba: END 1535d63cea 2011-05-28 kinaba: CASE(1) 1535d63cea 2011-05-28 kinaba: int n = 11; 1535d63cea 2011-05-28 kinaba: int _ = 2; 1535d63cea 2011-05-28 kinaba: END 1535d63cea 2011-05-28 kinaba: CASE(2) 1535d63cea 2011-05-28 kinaba: int n = 13; 1535d63cea 2011-05-28 kinaba: int _ = -1; 1535d63cea 2011-05-28 kinaba: END 1535d63cea 2011-05-28 kinaba: CASE(3) 1535d63cea 2011-05-28 kinaba: int n = 1234567; 1535d63cea 2011-05-28 kinaba: int _ = 1; 1535d63cea 2011-05-28 kinaba: END 1535d63cea 2011-05-28 kinaba: CASE(4) 1535d63cea 2011-05-28 kinaba: int n = 1; 1535d63cea 2011-05-28 kinaba: int _ = 2; 1535d63cea 2011-05-28 kinaba: END 1535d63cea 2011-05-28 kinaba: CASE(5) 1535d63cea 2011-05-28 kinaba: int n = 1000000000; 1535d63cea 2011-05-28 kinaba: int _ = -1; 1535d63cea 2011-05-28 kinaba: END 1535d63cea 2011-05-28 kinaba: 1535d63cea 2011-05-28 kinaba: } 1535d63cea 2011-05-28 kinaba: // END CUT HERE