#include #define questionMAX 100 /* answer = true := 以上 answer = false := 未満 */ class REALM { public: unsigned long long N_MAX, N_MIN, N_MEAN; void getMean(void) { N_MEAN = (N_MAX + N_MIN) / 2; } }; bool question(int x) { bool answer; std::cout << "? " << x << std::endl; std::cin >> answer; if(answer) { return true; } else { return false; } } REALM getRealm(REALM realm_prev, bool answer) { REALM realm_next; } int main(void) { REALM realm; realm.N_MAX = 1000000000; realm.N_MIN = 1; realm.getMean(); for(int i = 0; i < questionMAX; i ++) { if(question(realm.N_MEAN)) { realm.N_MIN = realm.N_MEAN; realm.getMean(); } else { realm.N_MAX = realm.N_MEAN - 1; realm.getMean(); } if(realm.N_MAX == realm.N_MIN) { std::cout << "! " << realm.N_MAX << std::endl << std::flush; break; } else if(realm.N_MIN == realm.N_MAX - 1) { if(question(realm.N_MAX)) { std::cout << "! " << realm.N_MAX << std::endl << std::flush; break; } else { std::cout << "! " << realm.N_MIN << std::endl << std::flush; break; } } //for debug //std::cout << realm.N_MIN << " <= x <= " << realm.N_MAX << std::endl; } return 0; }