Codeforces 727C Guess the Array
长度为\(n\)的数组,询问\(n\)次来求出数组中每一个数的值
我们可以先询问三次
\(a[1]+a[2]\)
\(a[1]+a[3]\)
\(a[2]+a[3]\)
然后根据这三次询问的结果,我们可以求出\(a[1]\)、\(a[2]\)、\(a[3]\)的值,然后我们就可以通过询问\(a[3]+a[4]\)、\(a[4]+a[5]\)、\(a[5]+a[6]\)……来求出\(a[4]\)、\(a[5]\)、\(a[6]\)……
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int read(){
int k=0; char c=getchar();
for(;c<'0'||c>'9';) c=getchar();
for(;c>='0'&&c<='9';c=getchar())
k=(k<<3)+(k<<1)+c-48;
return k;
}
int a[5010];
int main(){
int n=read();
cout<<"? "<<1<<" "<<2<<endl; fflush(stdout);
int x1=read();
cout<<"? "<<2<<" "<<3<<endl; fflush(stdout);
int x2=read();
cout<<"? "<<1<<" "<<3<<endl; fflush(stdout);
int x3=read();
a[1]=(x1+x2+x3)/2-x2;
a[2]=(x1+x2+x3)/2-x3;
a[3]=(x1+x2+x3)/2-x1;
for(int i=3;i<=n-1;i++){
cout<<"? "<<i<<" "<<i+1<<endl;
fflush(stdout); int x=read();
a[i+1]=x-a[i];
}
printf("! ");
for(int i=1;i<=n;i++)
printf("%d ",a[i]);
return 0;
}
Codeforces 727C Guess the Array的更多相关文章
- CodeForces 727C
zsy: Guess the Array Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ...
- Codeforces 442C Artem and Array(stack+贪婪)
题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...
- Codeforces Round #504 D. Array Restoration
Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...
- 【44.19%】【codeforces 727C】Guess the Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces 754A Lesha and array splitting(简单贪心)
A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...
- Codeforces 408 E. Curious Array
$ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...
- Educational Codeforces Round 11A. Co-prime Array 数学
地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...
- Codeforces 946G Almost Increasing Array (树状数组优化DP)
题目链接 Educational Codeforces Round 39 Problem G 题意 给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...
随机推荐
- Lightoj 1067【逆元模板(求C(N,M))】
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ...
- ugui mask失效
android平台 PlayerSettings-Resolution and Presentation-DisableDepth and Stencil这项勾选,mask失效
- 2013 Noip提高组 Day1
3285 转圈游戏 2013年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description ...
- [Xcode 实际操作]一、博主领进门-(5)检测运行中的模拟器在各个方向上的切换
目录:[Swift]Xcode实际操作 本文将演示Xcode的设备模拟器在各个方向上的切换和检测. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 检测运行中的模拟 ...
- IT兄弟连 JavaWeb教程 EL与JSTL表达式经典案例
案例需求:使用MVC模式编写一个程序,当发起一个deptList.do请求时,在servlet中准备一个部门列表对象,把这个列表对象放入request作用域中转发到deptlist.jsp,使用JST ...
- ISO 8 自适应cell
原文网址: http://www.cocoachina.com/ios/20141218/10687.html 在使用 table view 的时侯经常会遇到这样的需求:table view 的 ce ...
- bzoj 1494 生成树计数
坑了好多天的题,终于补上了 首先发现 \(i\) 这个点和 \(i-k\) 之前的点没有边,所以 \(i-k\) 之前的点肯定联通,只要处理中间 \(k\) 个点的联通状态就好了.我们用最小表示法,\ ...
- bzoj3626: [LNOI2014]LCA奇技淫巧+树剖+线段树
题目求[a,b]到c的lca深度之和 显然是一个满足区间减法的操作 于是简化为 [1,b]到c的lca深度之和 (然并卵╮(╯▽╰)╭)然后就用奇技淫巧发现 a和b的lca深度=先把根节点到a的路 ...
- 自己项目中PHP常用工具类大全分享
<?php /** * 助手类 * @author www.shouce.ren * */ class Helper { /** * 判断当前服务器系统 * @return string */ ...
- P1051 谁拿了最多奖学金——水题
题目描述 某校的惯例是在每学期的期末考试之后发放奖学金.发放的奖学金共有五种,获取的条件各自不同: 1) 院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1 ...