1ef2ecff66 2011-08-21 kinaba: #include <iostream> 1ef2ecff66 2011-08-21 kinaba: #include <sstream> 1ef2ecff66 2011-08-21 kinaba: #include <iomanip> 1ef2ecff66 2011-08-21 kinaba: #include <vector> 1ef2ecff66 2011-08-21 kinaba: #include <string> 1ef2ecff66 2011-08-21 kinaba: #include <map> 1ef2ecff66 2011-08-21 kinaba: #include <set> 1ef2ecff66 2011-08-21 kinaba: #include <algorithm> 1ef2ecff66 2011-08-21 kinaba: #include <numeric> 1ef2ecff66 2011-08-21 kinaba: #include <iterator> 1ef2ecff66 2011-08-21 kinaba: #include <functional> 1ef2ecff66 2011-08-21 kinaba: #include <complex> 1ef2ecff66 2011-08-21 kinaba: #include <queue> 1ef2ecff66 2011-08-21 kinaba: #include <stack> 1ef2ecff66 2011-08-21 kinaba: #include <cmath> 1ef2ecff66 2011-08-21 kinaba: #include <cassert> 1ef2ecff66 2011-08-21 kinaba: #include <cstring> 1ef2ecff66 2011-08-21 kinaba: using namespace std; 1ef2ecff66 2011-08-21 kinaba: typedef long long LL; 1ef2ecff66 2011-08-21 kinaba: typedef complex<double> CMP; 1ef2ecff66 2011-08-21 kinaba: 1ef2ecff66 2011-08-21 kinaba: class RotatedClock { public: 1ef2ecff66 2011-08-21 kinaba: string getEarliest(int hourHand, int minuteHand) 1ef2ecff66 2011-08-21 kinaba: { 1ef2ecff66 2011-08-21 kinaba: for(int h=0; h<12; ++h) 1ef2ecff66 2011-08-21 kinaba: for(int m=0; m<60; ++m) 1ef2ecff66 2011-08-21 kinaba: for(int offset=0; offset<360; offset+=30) { 1ef2ecff66 2011-08-21 kinaba: int hx = (hourHand + offset) % 360; 1ef2ecff66 2011-08-21 kinaba: int mx = (minuteHand + offset) % 360; 1ef2ecff66 2011-08-21 kinaba: if( match(h, m, hx, mx) ) { 1ef2ecff66 2011-08-21 kinaba: char buf[100]; 1ef2ecff66 2011-08-21 kinaba: sprintf(buf, "%02d:%02d", h, m); 1ef2ecff66 2011-08-21 kinaba: return buf; 1ef2ecff66 2011-08-21 kinaba: } 1ef2ecff66 2011-08-21 kinaba: } 1ef2ecff66 2011-08-21 kinaba: return string(); 1ef2ecff66 2011-08-21 kinaba: } 1ef2ecff66 2011-08-21 kinaba: 1ef2ecff66 2011-08-21 kinaba: bool match(int h, int m, int hx, int mx) 1ef2ecff66 2011-08-21 kinaba: { 1ef2ecff66 2011-08-21 kinaba: return (h*60+m)*360 == hx*(12*60) 1ef2ecff66 2011-08-21 kinaba: && m*360 == mx*60; 1ef2ecff66 2011-08-21 kinaba: } 1ef2ecff66 2011-08-21 kinaba: }; 1ef2ecff66 2011-08-21 kinaba: 1ef2ecff66 2011-08-21 kinaba: // BEGIN CUT HERE 1ef2ecff66 2011-08-21 kinaba: #include <ctime> 1ef2ecff66 2011-08-21 kinaba: double start_time; string timer() 1ef2ecff66 2011-08-21 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 1ef2ecff66 2011-08-21 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 1ef2ecff66 2011-08-21 kinaba: { os << "{ "; 1ef2ecff66 2011-08-21 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 1ef2ecff66 2011-08-21 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 1ef2ecff66 2011-08-21 kinaba: void verify_case(const string& Expected, const string& Received) { 1ef2ecff66 2011-08-21 kinaba: bool ok = (Expected == Received); 1ef2ecff66 2011-08-21 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 1ef2ecff66 2011-08-21 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 1ef2ecff66 2011-08-21 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 1ef2ecff66 2011-08-21 kinaba: #define END verify_case(_, RotatedClock().getEarliest(hourHand, minuteHand));} 1ef2ecff66 2011-08-21 kinaba: int main(){ 1ef2ecff66 2011-08-21 kinaba: 1ef2ecff66 2011-08-21 kinaba: CASE(0) 1ef2ecff66 2011-08-21 kinaba: int hourHand = 70; 1ef2ecff66 2011-08-21 kinaba: int minuteHand = 300; 1ef2ecff66 2011-08-21 kinaba: string _ = "08:20"; 1ef2ecff66 2011-08-21 kinaba: END 1ef2ecff66 2011-08-21 kinaba: CASE(1) 1ef2ecff66 2011-08-21 kinaba: int hourHand = 90; 1ef2ecff66 2011-08-21 kinaba: int minuteHand = 120; 1ef2ecff66 2011-08-21 kinaba: string _ = "11:00"; 1ef2ecff66 2011-08-21 kinaba: END 1ef2ecff66 2011-08-21 kinaba: CASE(2) 1ef2ecff66 2011-08-21 kinaba: int hourHand = 240; 1ef2ecff66 2011-08-21 kinaba: int minuteHand = 36; 1ef2ecff66 2011-08-21 kinaba: string _ = ""; 1ef2ecff66 2011-08-21 kinaba: END 1ef2ecff66 2011-08-21 kinaba: CASE(3) 1ef2ecff66 2011-08-21 kinaba: int hourHand = 19; 1ef2ecff66 2011-08-21 kinaba: int minuteHand = 19; 1ef2ecff66 2011-08-21 kinaba: string _ = ""; 1ef2ecff66 2011-08-21 kinaba: END 1ef2ecff66 2011-08-21 kinaba: CASE(4) 1ef2ecff66 2011-08-21 kinaba: int hourHand = 1; 1ef2ecff66 2011-08-21 kinaba: int minuteHand = 12; 1ef2ecff66 2011-08-21 kinaba: string _ = "00:02"; 1ef2ecff66 2011-08-21 kinaba: END 1ef2ecff66 2011-08-21 kinaba: /* 1ef2ecff66 2011-08-21 kinaba: CASE(5) 1ef2ecff66 2011-08-21 kinaba: int hourHand = ; 1ef2ecff66 2011-08-21 kinaba: int minuteHand = ; 1ef2ecff66 2011-08-21 kinaba: string _ = ; 1ef2ecff66 2011-08-21 kinaba: END 1ef2ecff66 2011-08-21 kinaba: CASE(6) 1ef2ecff66 2011-08-21 kinaba: int hourHand = ; 1ef2ecff66 2011-08-21 kinaba: int minuteHand = ; 1ef2ecff66 2011-08-21 kinaba: string _ = ; 1ef2ecff66 2011-08-21 kinaba: END 1ef2ecff66 2011-08-21 kinaba: */ 1ef2ecff66 2011-08-21 kinaba: } 1ef2ecff66 2011-08-21 kinaba: // END CUT HERE