Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) C
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.
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.
5
9
7
9
11
6
? 1 5
? 2 3
? 4 1
? 5 2
? 3 4
! 4 6 1 5 5
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[]); fflush(stdout);
printf("? 1 3\n\n");
scanf("%d",&a[]); fflush(stdout);
printf("? 2 3\n\n");
scanf("%d",&a[]); fflush(stdout);
b[]=(a[]+a[]-a[])/;
b[]=(a[]+a[]-a[])/;
b[]=a[]-b[];
for(int i=;i<=n;i++){
fflush(stdout);
printf("? 1 %d\n\n",i);
scanf("%d",&a[i]);
b[i]=a[i]-b[]; }
printf("\n! ");
for(int i=;i<=n-;i++){
printf("%d ",b[i]);
}
printf("%d\n",b[n]);
return ;
Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) C的更多相关文章
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) D
The organizers of a programming contest have decided to present t-shirts to participants. There are ...
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) B
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. ...
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) A
Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C
Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B
Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A
Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)
http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...
随机推荐
- Python序列——字符串
字符串 1 string模块预定义字符串 2 普通字符串与Unicode字符串 3 只适用于字符串的操作 4 原始字符串 5 Unicode字符串操作符 内建函数 1 标准类型函数与序列操作函数 2 ...
- codeforces 140B.New Year Cards 解题报告
题目链接:http://codeforces.com/problemset/problem/140/B 题目意思:给出 Alexander 和他的 n 个朋友的 preference lists:数字 ...
- SIP协议&开源SIP服务器搭建和客户端安装
1. SIP SIP 是一个应用层的控制协议,可以用来建立,修改,和终止多媒体会话,例如Internet电话 SIP在建立和维持终止多媒体会话协议上,支持五个方面: 1) 用户定位: 检查终端用户 ...
- leetcode398 and leetcode 382 蓄水池抽样算法
382. 链表随机节点 给定一个单链表,随机选择链表的一个节点,并返回相应的节点值.保证每个节点被选的概率一样. 进阶:如果链表十分大且长度未知,如何解决这个问题?你能否使用常数级空间复杂度实现? 示 ...
- vuex本地存储
vuex与localstorage 区别:vuex数据存储的内存,localstorage的数据存储在本地 应用场景:vuex用于组件之间的传值,localstorage用于不同页面之间的传值 永久性 ...
- Ubuntu12.04下安装、使用、卸载MySQL
转自:http://blog.csdn.net/yimi0903/article/details/11800713 一.安装 Step1:安装MySQL-server,mysql-client 执行以 ...
- A. Launch of Collider (#363 Div.2)
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- windows7激活及office2013激活
步骤 1.安装KMSpico 密码:dzit 2.安装.NET Framework 4 密码:vnus 3.解压KMSpico,运行文件,等待语音结束即可激活windows7及office2013 注 ...
- Mecanim Control
http://www.ufe3d.com/doku.php/mecanimcontrol Mecanim Control Your ultimate solution for Mecanim base ...
- Unity中HideInInspector和SerializeField
http://blog.sina.com.cn/s/blog_697b1b8c0102uxvn.html Unity会自动为Public变量做序列化,序列化的意思是说再次读取Unity时序列化的变量是 ...