time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).

In this problem you should guess an array a which is unknown for you. The only information you have initially is the length n of the array a.

The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices i and j (the indices should be distinct). Then your program should read the response: the single integer equals to ai + aj.

It is easy to prove that it is always possible to guess the array using at most n requests.

Write a program that will guess the array a by making at most n requests.

Interaction

In each test your program should guess a single array.

The input starts with a line containing integer n (3 ≤ n ≤ 5000) — the length of the array. Your program should read it at first.

After that your program should print to the standard output the requests about the sum of two elements or inform that the array is guessed.

In case your program is making a request to ask the sum of two elements, it should print line in the format “? i j” (i and j are distinct integers between 1 and n), where i and j are indices in the array a.

In case your program informs that the array is guessed, it should print line in the format “! a1 a2 … an” (it is guaranteed that all ai are positive integers not exceeding 105), where ai is the i-th element of the array a.

The response on a request is a single integer equal to ai + aj, printed on a separate line.

Your program can do at most n requests. Note that the final line «! a1 a2 … an» is not counted as a request.

Do not forget about flush operation after each printed line.

After you program prints the guessed array, it should terminate normally.

Example

input

5

9

7

9

11

6

output

? 1 5

? 2 3

? 4 1

? 5 2

? 3 4

! 4 6 1 5 5

Note

The format of a test to make a hack is:

The first line contains an integer number n (3 ≤ n ≤ 5000) — the length of the array.

The second line contains n numbers a1, a2, …, an (1 ≤ ai ≤ 105) — the elements of the array to guess.

【题解】



交互题;

printf(“? i j\n”);

fflush(stdout);

然后scanf(“%d”,&d);

就能把系统给你的东西输入到d这个变量里了。

让你猜一个序列a[1..n]。

每次你可以询问任意两个数字的和。

最多使用n次询问,求出所有的序列;

先弄出前3个

询问

1 2

1 3

2 3

然后

a1+a2=k1;

a1+a3=k2;

a2+a3=b;



a3 = (b+k2-k1)/2

a2 = (b+k1-k2)/2;(路人甲)->其实a2=b-a3更简单,(我,一个独裁者)->滚;

a1 = k1-a2;

然后咱们就用3次询问得到a[1..3]了;

然后for(int i = 4;i <= n;i++)

printf(“? 1 %d\n”,i);

询问 1 和(4..n);

然后减去a1就是a[4..n]了;

刚好用完n次询问;

那个询问里面好像要输出空行,不然会出现的错误(Idleness limit exceeded on pretest 1);当然不知道是不是这个原因,反正输出空行的地方按照样例的输出的输出吧

  1. #include <cstdio>
  2. const int MAXN = 6000;
  3. int n,a1;
  4. int a[MAXN];
  5. int main()
  6. {
  7. //freopen("F:\\rush.txt", "r", stdin);
  8. //freopen("input.txt", "r", stdin);
  9. //freopen("output.txt", "w", stdout);
  10. scanf("%d", &n);
  11. printf("\n? 1 2\n");
  12. fflush(stdout);
  13. int k1;
  14. scanf("%d", &k1);
  15. printf("\n? 1 3\n");
  16. fflush(stdout);
  17. int k2;
  18. scanf("%d", &k2);
  19. printf("\n? 2 3\n");
  20. fflush(stdout);
  21. int b;
  22. scanf("%d", &b);
  23. a[2] = (b + k1 - k2) / 2;
  24. a[3] = (b + k2 - k1) / 2;
  25. a[1] = k1 - a[2];
  26. for (int i = 4; i <= n; i++)
  27. {
  28. printf("\n? %d %d\n", 1, i);
  29. fflush(stdout);
  30. scanf("%d", &a[i]);
  31. a[i] -= a[1];
  32. }
  33. printf("\n");
  34. printf("! ");
  35. for (int i = 1; i <= n - 1; i++)
  36. printf("%d ", a[i]);
  37. printf("%d\n", a[n]);
  38. return 0;
  39. }

【44.19%】【codeforces 727C】Guess the Array的更多相关文章

  1. 【44.19%】【codeforces 608D】Zuma

    time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【19.77%】【codeforces 570D】Tree Requests

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【19.46%】【codeforces 551B】ZgukistringZ

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【44.64%】【codeforces 743C】Vladik and fractions

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【77.78%】【codeforces 625C】K-special Tables

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. 【30.43%】【codeforces 746C】Tram

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  9. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

随机推荐

  1. jquery设置attr属性值

    1.返回属性值 $(selector).attr(attribute); 2.设置属性值 $(selector).attr(attribute,value); 3.设置多个属性值 $(selector ...

  2. oled屏幕模块

    oled屏幕模块似乎是厂家提供的 也许可以根据屏幕驱动芯片去写 根据现在了解的芯片一般有两个:SH1106和SSD1306 不过这次我们用的是SSD1306芯片驱动的屏幕 下面是从裸屏到模块的pcb: ...

  3. windows下安装emscripten

    windows下安装emscripten windows下安装emscripten需要python.git环境 python安装 git安装 开始安装 # 1.克隆emsdk git clone ht ...

  4. 深入理解线程本地变量ThreadLocal

    ThreadLocal理解: 假设在多线程并发环境中.一个可变对象涉及到共享与竞争,那么该可变对象就一定会涉及到线程间同步操作,这是多线程并发问题. 否则该可变对象将作为线程私有对象,可通过Threa ...

  5. __block typeof的说明

    1. block不是Object对象,所以对retain无效,要想保留block生命周期,最好通过copy来实现,当然copy后,要记得release. 2.一般被block的应用的对象,retain ...

  6. cpu信息

    在linux系统下能够通过cat /proc/cpuinfo来查看本机上cpu的相关信息,通过processor能够推断逻辑cpu的个数,physical id能够推断物理cpu的个数,通过cpu c ...

  7. apache与IIS共用80端口冲突解决方法

    如果同一台电脑安装了apache和iis,会提示80端口冲突,如何解决apache与iis 80端口冲突的问题呢,并且同时使用apache和iis 将apache设为使用80端口,IIS使用其它端口, ...

  8. 自定义npm包的创建、发布、更新和撤销

    大纲 1.准备2.自定义npm包3.发布自定义npm包4.引用npm包5.更新npm包6.撤销发布的npm包 简书原文 https://www.jianshu.com/p/d737bc5df5b7 1 ...

  9. [Nuxt] Build a Navigation Component in Vue.js and Use in a Nuxt Layout

    You can isolate parts of templates you want to re-use into components, but you can also reuse those ...

  10. VS_VERSION_INFO

    VS_VERSION_INFO这里可以修改ocx的版本号