题目传送门

长度为\(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. PhpStorm下载、破解

    下载 去官网下载新版phpstorm 破解 1.打开编辑器, Help->Register->License server,输入http://idea.codebeta.cn (支持10. ...

  2. lightoj 1078【同余定理】

    题意: 给你一个n和一个数 digit ,问你最少需要多少个 digit 使得整除于n; 思路: 同余定理(a+b)%n=(a%n+b%n)%n; (m%n+m%n*10+m%n*100+m%n*10 ...

  3. Matlab图像处理相关

    相关函数: 读取:imread() %参数为文件名(路径)或url,格式等 写入:imwrite() %参数为写入数据矩阵,写入文件名(路径),格式等 显示:imshow() %显示由输入决定,属性自 ...

  4. 小试JVM工具

    一.前言 工欲善其事必先利其器,jdk自带了很多工具,利用好这些工具能够帮我们获取想要的数据(运行日志.异常堆栈.GC日志.线程快照.堆转储快照等),从而快速的分析数据.定位问题. 二.jps:虚拟机 ...

  5. bzoj3427:[POI2013]BAJ-Bytecomputer

    传送门 很显然有一个结论:最大不过1,最小不过-1 然后dp,设\(f[i][j]\)为满足前\(i\)个不下降,当前放的是\(j-2\),转移就比较好想了 具体方程看代码吧,终于有一个自己会写的题了 ...

  6. 在centos7下搭建nginx环境,并配置负载均衡,最终能达到通过域名直接访问的目的

    1.关于nginx:个人理解的nginx它的主要用途就是负载均衡,当然可能还有其他一些功能可能我们不长用到,我们通过nginx可以干什么呢?为什么要引入它呢?原因是当有高并发访问服务器时,服务器可能会 ...

  7. Verify the Developer App certificate for youraccount is trusted on your device

    运行时报错-Verify the Developer App certificate for youraccountis   trusted on your device. Open Settings ...

  8. jmeter diff测试

    1.准备接口数据(对比字段,即json数据中需要提取的key对应的值进行对比) 2.配置获取EXCEL数据 3.新建线程,并建两个http请求,分别用于请求新旧接口 4.提取需要对比的内容 5.赋值变 ...

  9. [软件工程基础]PhyLab 需求与功能分析改进文档

    NABCD 模型 Need 需求 根据 Default 的需求文档,物理实验网站对于北航大二学生完成物理实验有较大的帮助,反馈较好.由于在 2016-2017 春季学期,网站数据库因为不明原因被删除了 ...

  10. 前端之CSS布局模型

    一.css布局模型: 流动模型(Flow) 浮动模型(Float) 层模型(Layer) 1.流动模型: 页面在没有设置任何css样式,元素按照本身的特性在浏览器中显示,这样的布局模型称为流动模型: ...