CodeForce727C. Guess the Array---交互题

题目链接:http://codeforces.com/contest/727/problem/C

题意:交互题; 
printf(“? i j\n”); 
fflush(stdout); 
然后scanf(“%d”,&d); 
就能把系统给你的东西输入到d这个变量里了。 
让你猜一个序列a[1..n]。 
每次你可以询问任意两个数字的和。 
最多使用n次询问,求出所有的序列; 

太高大上第一次见;其实就是每次你问任意两个数的和,然后系统告诉你,然后存到一个数里面,然后只能问n次,就原数组是多少;

#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
#define mod 1000000007
typedef long long LL;
//////////////////////////////////////////////////////////////
const int INF = 0x3f3f3f3f;
const int N = 5521;
const double eps = 1e-8;

int n, a[N];

int main()
{
    scanf("%d", &n);

    for(int i=1; i<n; i++)
    {
        printf("? 1 %d\n", i+1);
        fflush(stdout);
        scanf("%d", &a[i]);
    }
    printf("? 2 3\n");
    fflush(stdout);
    scanf("%d", &a[n]);
    int x = (a[1]+a[2]-a[n])/2;
    printf("! %d", x);
    fflush(stdout);

    for(int i=1; i<n; i++)
    {
        printf(" %d", a[i]-x);
        fflush(stdout);
    }
    printf("\n");
    fflush(stdout);
    return 0;
}
View Code

 

posted @ 2016-10-23 15:30  西瓜不懂柠檬的酸  Views(211)  Comments(0Edit  收藏  举报
levels of contents