题目传送门

长度为\(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. SPOJ PHT【二分】+SPOJ INUM【最小/大值重复】

    BC 两道其实都是水 没有完整地想好直接就码出事情.wa了一次以后要找bug,找完要把思路理的非常清楚 SPOJ PHT[二分] #include<bits/stdc++.h> using ...

  2. hyperledger fabric 1.0.5 分布式部署 (七)

    fabric 使用 fabric-ca 服务 准备部分 首先需要用户从github上download fabric-ca 的工程代码 cd $GOPATH/src/github.com/hyperle ...

  3. hyperledger fabric 1.0.5 分布式部署 (五)

    梳理fabric e2e_cli 测试程序的具体步骤 作者在 hyperledger fabric 1.0.5 分布式部署 (一)中给读者们介绍了如何从零开始部署一个测试的 demo 环境,如果细心的 ...

  4. C 语言实例 - 二进制与十进制相互转换

    C 语言实例 - 二进制与十进制相互转换 C 语言实例 C 语言实例 二进制转与十进制相互转换. 实例 - 二进制转换为十进制 #include <stdio.h> #include &l ...

  5. 50 个加速包都抢不到车票,还不如这个 Python 抢票神器!

    又到了一年一度的抢票大战,本来就辛苦劳累了一年,想着可以早点订到票跟家里人团聚.所以有挺多的人,宁愿多花些钱去找黄牛买票.但今年各种抢票软件的横行,还有官方出的加速包,导致连黄牛都不敢保证能买到票.你 ...

  6. iOS开发 - 多线程实现方案之NSThread篇

    NSThread API //类方法:创建一个线程 + (void)detachNewThreadWithBlock:(void (^)(void))block API_AVAILABLE(macos ...

  7. 【bzoj3033】太鼓达人

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 521  Solved: 399[Submit][Status][Discuss] ...

  8. hdu 5971 Wrestling Match 判断能否构成二分图

    http://acm.hdu.edu.cn/showproblem.php?pid=5971 Wrestling Match Time Limit: 2000/1000 MS (Java/Others ...

  9. log4j.properties 打印到控制台 写法

    # 日志输出级别(INFO)和输出位置(stdout,R)log4j.rootLogger=INFO, stdout # 日志输出位置为控制台log4j.appender.stdout=org.apa ...

  10. 阿里云栖社区dubbo 资源整理

    1.apache dubbo pdf git 地址:https://github.com/dubbo/awesome-dubbo/tree/master/slides/meetup/201905%40 ...