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);当然不知道是不是这个原因,反正输出空行的地方按照样例的输出的输出吧

#include <cstdio>

const int MAXN = 6000;

int n,a1;
int a[MAXN]; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
scanf("%d", &n);
printf("\n? 1 2\n");
fflush(stdout);
int k1;
scanf("%d", &k1);
printf("\n? 1 3\n");
fflush(stdout);
int k2;
scanf("%d", &k2);
printf("\n? 2 3\n");
fflush(stdout);
int b;
scanf("%d", &b);
a[2] = (b + k1 - k2) / 2;
a[3] = (b + k2 - k1) / 2;
a[1] = k1 - a[2];
for (int i = 4; i <= n; i++)
{
printf("\n? %d %d\n", 1, i);
fflush(stdout);
scanf("%d", &a[i]);
a[i] -= a[1];
}
printf("\n");
printf("! ");
for (int i = 1; i <= n - 1; i++)
printf("%d ", a[i]);
printf("%d\n", a[n]);
return 0;
}

【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. iOS_05_变量的内存分析、Scanf函数

    一.变量的内存分析 1.字节和地址 * 为了更好地理解变量在内存中得存储细节,先来认识一下内存中得”字节“和”地址“. * 内存以字节为单位 * 不同类型占用的字节是不一样的,数据越大,所需的字节数九 ...

  2. Js里面的arguments

    了解这个对象之前先来认识一下javascript的一些功能: 其实Javascript并没有重载函数的功能,但是Arguments对象能够模拟重载.Javascrip中国每个函数都会有一个Argume ...

  3. POJ 1064 Cable master 浮点数二分

    http://poj.org/problem?id=1064 题目大意: 有N条绳子,他们的长度分别为Li,如果从它们中切割出k条长度相同的绳子的话,这K条绳子每条能有多长? 思路: 二分,设答案为m ...

  4. HTTP详解--请求、响应、缓存

    1. HTTP请求格式 做过Socket编程的人都知道,当我们设计一个通信协议时,“消息头/消息体”的分割方式是很常用的,消息头告诉对方这个消息是干什么的,消息体告诉对方怎么干.HTTP协议传输的消息 ...

  5. promis:异步编程

    promise对象用于延迟计算和异步计算:一个promise对象代表着一个还未完成,但预期将来完成的操作 Image.png Image.png 打印结果如下: <!DOCTYPE html&g ...

  6. C# is 和 as的用法

    try            {                if (sender is Button)                {                    Button dd ...

  7. TCP的可靠传输机制(简单好理解:分段与流,滑窗,连接,流量控制,重新发送,堵塞控制)

    TCP的几大模块:分段与流,滑窗,连接,流量控制,重新发送,堵塞控制. 1.checksum:在发送TCP报文的时候,里面的信息可能会因为环境的问题,发送变化,这时,接收信号的时候就需要通过check ...

  8. RMAN备份到NFS,报错 ORA-27054

    使用RMAN备份数据库到NFS挂载到的本地目录/backup 失败,失败提示如下: RMAN-03009: failure of backup command on ORA_DISK_1 channe ...

  9. RTC时钟和BKP的配置stm32

    摘自:https://blog.csdn.net/gtkknd/article/details/52233605 RTC和后备寄存器通过一个开关供电,在VDD有效的时候选择VDD供电,否则选择VBAT ...

  10. 使用前端后台管理模板库admin-lte(转)

    使用前端后台管理模板库admin-lte 使用前端后台管理模板库admin-lte 安装 搭建环境 安装 安装admin-lte,可以通过以下几种办法安装,下图是GitHub中admin-lte的主页 ...