题目传送门

长度为\(n\)的数组,询问\(n\)次来求出数组中每一个数的值

我们可以先询问三次

  1. \(a[1]+a[2]\)

  2. \(a[1]+a[3]\)

  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的更多相关文章

  1. CodeForces 727C

    zsy: Guess the Array Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ...

  2. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  3. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  4. 【44.19%】【codeforces 727C】Guess the Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 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 ...

  6. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  7. Codeforces 408 E. Curious Array

    $ >Codeforces \space 408 E. Curious Array<$ 题目大意 : 有一个长度为 \(n\) 的序列 \(a\) ,\(m\) 次操作,每一次操作给出 \ ...

  8. 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 ...

  9. Codeforces 946G Almost Increasing Array (树状数组优化DP)

    题目链接   Educational Codeforces Round 39 Problem G 题意  给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...

随机推荐

  1. LVS-DR VIP和RIP不同网段的配置方法

    http://blog.itpub.net/25723371/viewspace-1446935/

  2. day04 异常

  3. [題解](最短路/二分)luogu_P1462通往奧格瑞瑪的道路

    看到最大的最小值應該想到二分答案,這樣就解決了最小點權的問題,判血量就很好說,直接比較就行, 一個點是二分點權數組,複製一份然後排序,二分下標,速度較快 這麼簡單的題我竟然寫了這麼長時間 #inclu ...

  4. Django (五) modeld进阶

    day 05 models进阶 1.models基本操作   django中遵循 Code Frist 的原则,即:根据代码中定义的类来自动生成数据库表. 对于ORM框架里: 我们写的类表示数据库的表 ...

  5. Qt 2D绘图之二:抗锯齿渲染和坐标系统

    一.抗锯齿渲染 1.1 逻辑绘图 图形基元的大小(宽度和高度)始终与其数学模型相对应,下图示意了忽略其渲染时使用的画笔的宽度的样子. 1.2 物理绘图(默认情况) 在默认的情况下,绘制会产生锯齿,并且 ...

  6. Guard Duty (medium) Codeforces - 958E2 || (bzoj 2151||洛谷P1792) 种树 || 编译优化

    https://codeforces.com/contest/958/problem/E2 首先求出N个时刻的N-1个间隔长度,问题就相当于在这些间隔中选K个数,相邻两个不能同时选,要求和最小 方法1 ...

  7. LM358与TL431验证

  8. nodejs 学习(4) express+mongoose

    一.关于安装和启动: 1.设置环境变量:D:\Program Files\MongoDB\bin 2.启动时需要cd到bin 目录,然后 mongod --dbpath "D:\mongdb ...

  9. Windows server 2003 + IIS6 搭建Asp.net MVC运行环境

    安装.Net Framework4.0.下载地址:http://www.microsoft.com/zh-cn/download/details.aspx?id=17718 安装WindowsServ ...

  10. 前端之CSS盒模型介绍

    css盒模型 css盒模型是css的基石,盒模型由content(主体内容),padding(补白,填充),border(边框),margin(外间距); 1.content: width:数值+单位 ...