Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) C
2017-07-26 23:04
537 查看
This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should usefflush(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 bedistinct). 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
output
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.
题意:给出未知的两个数和ai,大概给n次要你求出整个数组,还得脑补出这些数字和是哪两个数字加的
解法:
1 我们构造前三个数字b1 b2 b3(稍微计算一下),然后第4个数字开始就是拿a4-b1、、a5-b1。。。
2 额,这输入老是有问题。。。不过思路一定是对的
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 bedistinct). 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.
题意:给出未知的两个数和ai,大概给n次要你求出整个数组,还得脑补出这些数字和是哪两个数字加的
解法:
1 我们构造前三个数字b1 b2 b3(稍微计算一下),然后第4个数字开始就是拿a4-b1、、a5-b1。。。
2 额,这输入老是有问题。。。不过思路一定是对的
fflush(stdout); scanf("%d",&n); printf("\n"); fflush(stdout); printf("? 1 2\n\n"); scanf("%d",&a[1]); fflush(stdout); printf("? 1 3\n\n"); scanf("%d",&a[2]); fflush(stdout); printf("? 2 3\n\n"); scanf("%d",&a[3]); fflush(stdout); b[3]=(a[2]+a[3]-a[1])/2; b[2]=(a[1]+a[3]-a[2])/2; b[1]=a[1]-b[2]; for(int i=4;i<=n;i++){ fflush(stdout); printf("? 1 %d\n\n",i); scanf("%d",&a[i]); b[i]=a[i]-b[1]; } printf("\n! "); for(int i=1;i<=n-1;i++){ printf("%d ",b[i]); } printf("%d\n",b ); return 0;
相关文章推荐
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) A
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) D
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2)A
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) B
- Technocup 2017 - Elimination Round 1 (Rated for Div. 2) C. Guess the Array 交互题+解n元方程组
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3)
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E
- Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
- codeforces Technocup 2017 - Elimination Round 2/Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) 题解
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)
- 【解题报告】Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) 题解
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 – Elimination Round 2) A. Interview wi
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) F
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) 圣诞之夜!