28a087506a 2011-09-21 kinaba: #include <iostream> 28a087506a 2011-09-21 kinaba: #include <sstream> 28a087506a 2011-09-21 kinaba: #include <iomanip> 28a087506a 2011-09-21 kinaba: #include <vector> 28a087506a 2011-09-21 kinaba: #include <string> 28a087506a 2011-09-21 kinaba: #include <map> 28a087506a 2011-09-21 kinaba: #include <set> 28a087506a 2011-09-21 kinaba: #include <algorithm> 28a087506a 2011-09-21 kinaba: #include <numeric> 28a087506a 2011-09-21 kinaba: #include <iterator> 28a087506a 2011-09-21 kinaba: #include <functional> 28a087506a 2011-09-21 kinaba: #include <complex> 28a087506a 2011-09-21 kinaba: #include <queue> 28a087506a 2011-09-21 kinaba: #include <stack> 28a087506a 2011-09-21 kinaba: #include <cmath> 28a087506a 2011-09-21 kinaba: #include <cassert> 28a087506a 2011-09-21 kinaba: #include <cstring> 28a087506a 2011-09-21 kinaba: using namespace std; 28a087506a 2011-09-21 kinaba: typedef long long LL; 28a087506a 2011-09-21 kinaba: typedef complex<double> CMP; 28a087506a 2011-09-21 kinaba: 28a087506a 2011-09-21 kinaba: class BinaryCards { public: 28a087506a 2011-09-21 kinaba: long long largestNumber(long long A_, long long B_) 28a087506a 2011-09-21 kinaba: { 28a087506a 2011-09-21 kinaba: unsigned long long A = A_; 28a087506a 2011-09-21 kinaba: unsigned long long B = B_; 28a087506a 2011-09-21 kinaba: string sa; 28a087506a 2011-09-21 kinaba: for(int i=0; (1ULL<<i)<=A; ++i) 28a087506a 2011-09-21 kinaba: sa = char('0' + ((A>>i)&1)) + sa; 28a087506a 2011-09-21 kinaba: string sb; 28a087506a 2011-09-21 kinaba: for(int i=0; (1ULL<<i)<=B; ++i) 28a087506a 2011-09-21 kinaba: sb = char('0' + ((B>>i)&1)) + sb; 28a087506a 2011-09-21 kinaba: sa = string(sb.size()-sa.size(), '0') + sa; 28a087506a 2011-09-21 kinaba: 28a087506a 2011-09-21 kinaba: string sc; 28a087506a 2011-09-21 kinaba: for(int i=0; i<sb.size(); ++i) 28a087506a 2011-09-21 kinaba: if( sa[i] == sb[i] ) 28a087506a 2011-09-21 kinaba: sc += sa[i]; 28a087506a 2011-09-21 kinaba: else { 28a087506a 2011-09-21 kinaba: sc += string(sb.size()-i, '1'); 28a087506a 2011-09-21 kinaba: break; 28a087506a 2011-09-21 kinaba: } 28a087506a 2011-09-21 kinaba: 28a087506a 2011-09-21 kinaba: LL value = 0; 28a087506a 2011-09-21 kinaba: for(int i=0; i<sc.size(); ++i) 28a087506a 2011-09-21 kinaba: if( sc[sc.size()-i-1] == '1' ) 28a087506a 2011-09-21 kinaba: value |= (1LL << i); 28a087506a 2011-09-21 kinaba: return value; 28a087506a 2011-09-21 kinaba: } 28a087506a 2011-09-21 kinaba: }; 28a087506a 2011-09-21 kinaba: 28a087506a 2011-09-21 kinaba: 28a087506a 2011-09-21 kinaba: 28a087506a 2011-09-21 kinaba: // Powered by FileEdit 28a087506a 2011-09-21 kinaba: // Powered by TZTester 1.01 [25-Feb-2003] : <cafelier&naoya_t>-custom 28a087506a 2011-09-21 kinaba: // Powered by CodeProcessor