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需要改变的最小元素个数. ...
随机推荐
- codeforces743D 【DFS】
题意: 给你一棵以1为root的根,然后让你求两棵不相交子树的最大和: 思路: DFS,主要就是你一定得使两棵子树不相交: 对于一个顶点u,维护以u为根的最大子树和. ①:包含u,即所有的结点和. ② ...
- laravel 路由设置
目录 routes\web.php 初始路由,直接渲染视图welcome,即V层 '/'为路径:www.xxx.com/ Route::get('/', function () { return ...
- Dota2技能系统设计分析
http://blog.csdn.net/langresser_king/article/details/46776701 前两周写完了新游戏的技能系统.虽然也算灵活,但是跟Dota2的技能系统设计比 ...
- [Xcode 实际操作]一、博主领进门-(3)使用资源文件夹(Assets.xcassets)导入并管理图片素材
目录:[Swift]Xcode实际操作 本文将演示如何使用资源文件夹(Assets.xcassets)导入并管理图片素材. [Assets.xcassets]资源文件夹可以方便的进行图片的管理, 在读 ...
- assembly x86(nasm)修改后的日常
data segment ENG db 'SUNdayS Coming I Wanna Drive My Car,SUN,SUN$' ;9,3 sun1 db 'SUN' swcount db 0ah ...
- 【IDEA】关于 IDEA 中新建 web 项目的 webapp 文件夹没有小蓝点 ,启动服务,访问不到解决方案
问题描述: 新建的 maven 的 Module 项目,webapp 文件夹也是在创建完项目后手动添加的,出现了 webapp 文件夹不能被识别的情况. 解决方案: 第一步: 选中项目按 F4 键, ...
- 01 | Jewels and Stones
Question You're given strings J representing the types of stones that are jewels, and S representing ...
- DRF教程4-视图集和路由类
rest框架包括一个处理viewset的抽象,允许开发人员集中精力处理api交互和建模,url构造都根据常见方式自动处理. ViewSet类 几乎和VIew类一样,不过它提供read,update这样 ...
- HDU 1875(最小生成树)
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> ...
- 【bzoj3033】太鼓达人
3033: 太鼓达人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 521 Solved: 399[Submit][Status][Discuss] ...