题意
有n个箱子,Chanek猜测每个箱子有多少个火烈鸟,必须猜对。
思路
我们要先唯一确定前面三个箱子里有多少个火烈鸟,然后已知前面箱子里的火烈鸟个数,再用 [i - 1, i]这个区间去求出i箱子有多少个火烈鸟。
AC代码
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
int ans[maxn];
void solve() {
int n, s13, s23, s12, x;
scanf("%d", &n);
printf("? %d %d\n", 1, 3);
fflush(stdout);
scanf("%d", &s13);
printf("? %d %d\n", 2, 3);
fflush(stdout);
scanf("%d", &s23);
printf("? %d %d\n", 1, 2);
fflush(stdout);
scanf("%d", &s12);
ans[1] = s13 - s23; ans[2] = s12 - ans[1]; ans[3] = s23 - ans[2];
for (int i = 4; i <= n; ++i) {
printf("? %d %d\n", i - 1, i);
fflush(stdout);
scanf("%d", &x);
ans[i] = x - ans[i - 1];
}
for (int i = 1; i <= n; ++i) {
if (i == 1) {
printf("! %d", ans[i]);
} else {
printf(" %d", ans[i]);
}
fflush(stdout);
}
puts("");
fflush(stdout);
}
int main() {
solve();
return 0;
}