显示原始代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int C = min(8 * n, 5000);
double max_f = 0;
int best_m = 1;
int max_possible_m = (int)sqrt(C);
for (int m_candidate = 1; m_candidate <= max_possible_m; ++m_candidate) {
int cost = m_candidate * m_candidate;
if (cost > C)
continue;
int remaining = C - cost;
double current_f = (double)remaining * (m_candidate + 1) / (2.0 * n);
if (current_f > max_f || (current_f == max_f && m_candidate > best_m)) {
max_f = current_f;
best_m = m_candidate;
}
}
int m = best_m;
cout << "! " << m << endl;
cout.flush();
int remaining_coins = C - m * m;
int max_guess = 0;
for (int i = 0; i < remaining_coins; ++i) {
cout << "? 1" << endl;
cout.flush();
int current_max;
cin >> current_max;
if (current_max == -1) {
return 0;
}
if (current_max > max_guess) {
max_guess = current_max;
}
}
cout << "! " << max_guess << endl;
cout.flush();
return 0;
}