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,到每 ...
随机推荐
- ffmpeg av_interleaved_write_frame Operation not permitted
今天在使用ffmpeg时出现了Operation not permitted通过增加打印信息发现是在av_interleaved_write_frame出现的问题, 昨天还没出现这个问题,很奇怪,就把 ...
- hdu 1047 Integer Inquiry(大数)
题意:整数大数加法 思路:大数模板 #include<iostream> #include<stdio.h> #include<stdlib.h> #include ...
- hdu-5753 Permutation Bo(概率期望)
题目链接: Permutation Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- Linux-Nginx和NFS
1 虚拟化 查看系统信息 cat /proc/meninfo cat /proc/cpuinfo 其中 flags里面的信息可以查看该cpu是否支持虚拟化 flags上有vmx svm等表示可以虚拟化 ...
- js 常见的小数取整问题
1.四舍五入取整 Math.round(5/2) // 3 2.直接去掉小数,取整 parseInt(5/2); // 2 3.向上取整,有小数整数部分就加1 Math.ceil(1/3 ...
- Awesome Flask Awesome
A curated list of awesome Flask resources and plugins Awesome Flask Framework Admin interface Authen ...
- FTP:文件传输协议(指令及响应代码)
文件传输协议(FTP)使得主机间可以共享文件. FTP 使用 TCP 生成一个虚拟连接用于控制信息,然后再生成一个单独的 TCP 连接用于数据传输.控制连接使用类似 TELNET 协议在主机间交换命令 ...
- windows下的套接字IO模型
一般情况下,IO操作的行为受两种因素的影响: IO操作对象的类型(阻塞还是非阻塞) 获取IO操作结果的方式(同步还是异步). 同步就是指操作的发起和操作结果的获取由调用者完成. 异步指操作发起由调用方 ...
- Oracle数据库当前连接数、最大连接数的查询与设置
在开发过程中Oracle数据库有时候连得上,有时候又连不上,提示如下异常“ORA-12519: TNS:no appropriate service handler found 解决”,可能是数据库上 ...
- sybase SQL记录
在一个表中复制一行,主键是MLID ';