题目传送门:http://codeforces.com/problemset/problem/727/C
题意:一道交互题,有n个数,你可以询问n次任意两个数的和(这两个数不可以相等),然后猜出n个数分别是多少
思路:之前从没做过交互题,其实很简单。一问一答,先问sum1,2 ,sum2,3,sum1,3算出来a1,a2,a3然后接着问sum3,4,sum4,5........分别算出来a4,a5...就行了
代码如下:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <cstdlib>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll long long
#define ull unsigned long long
#define mem(n,v) memset(n,v,sizeof(n))
#define MAX 5005
#define MAXN 10005
#define PI 3.1415926
#define E 2.718281828459
#define opnin freopen("input.txt","r",stdin)
#define opnout freopen("output.txt","w",stdout)
#define clsin fclose(stdin)
#define clsout fclose(stdout)
#define haha1 cout << "haha1"<< endl
#define haha2 cout << "haha2"<< endl
#define haha3 cout << "haha3"<< endl
const int INF = 0x3f3f3f3f;
const ll INFF = 0x3f3f3f3f3f3f3f3f;
const double pi = 3.141592653589793;
const double inf = 1e18;
const double eps = 1e-8;
const ll mod = 1e18;
const ull mx = 133333331;
/**************************************************************************/
int main()
{
int sum[MAX];
// opnin;
// opnout;
int ans[MAX];
mem(ans,0);
int n;
scanf("%d",&n);
printf("? 1 2\n");
fflush(stdout);
scanf("%d",&sum[0]);
printf("? 2 3\n");
fflush(stdout);
scanf("%d",&sum[1]);
printf("? 1 3\n");
fflush(stdout);
scanf("%d",&sum[2]);
int sum_123 = sum[0] + sum[1] + sum[2];
sum_123 /= 2;
ans[2] = sum_123 - sum[0];
ans[0] = sum_123 - sum[1];
ans[1] = sum_123 - sum[2];
for(int i=3;i<n;i++){
int s;
printf("? %d %d\n",i,i+1);
fflush(stdout);
scanf("%d",&s);
ans[i] = s - ans[i-1];
}
printf("!");
for(int i=0;i<n;i++){
printf(" %d",ans[i]);
}
// clsin;
// clsout;
}