CF1425F Flamingoes of Mystery 题解
前置知识
解法
令 \(sum_k=\sum\limits_{i=1}^{k} a_k\)。考虑分别输入 \(sum_2 \sim sum_n\),故可以由于差分知识得到 \(a_i=sum_i-sum_{i-1}(3 \le i \le n)\),接着输入 \(a_2+a_3\) 的值从而求出 \(a_2=sum_3-a_3,a_1=sum_2-a_2\)。
同时因为是交互题,记得清空缓冲区。 C++ 可以使用 fflush(stdout); 进行清空缓冲区。
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sort stable_sort
#define endl '\n'
int sum[2001],a[2001];
int main()
{
int n,i,num;
cin>>n;
cout<<"? 1 2"<<endl;
fflush(stdout);
cin>>sum[2];
for(i=3;i<=n;i++)
{
cout<<"? 1 "<<i<<endl;
fflush(stdout);
cin>>sum[i];
a[i]=sum[i]-sum[i-1];
}
cout<<"? 2 3"<<endl;
fflush(stdout);
cin>>num;
a[2]=num-a[3];
a[1]=sum[2]-a[2];
cout<<"! ";
for(i=1;i<=n;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
CF1425F Flamingoes of Mystery 题解的更多相关文章
- 算法(第四版)C# 习题题解——1.2
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 这一节内容可能会用到的库文件有 ...
- 算法(第四版)C# 习题题解——1.1
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 善用 Ctrl + F 查找题 ...
- HNOI2018简要题解
HNOI2018简要题解 D1T1 寻宝游戏 题意 某大学每年都会有一次 Mystery Hunt 的活动,玩家需要根据设置的线索解谜,找到宝藏的位置,前一年获胜的队伍可以获得这一年出题的机会. 作为 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
随机推荐
- java进阶(32)--Collections工具类
一.简介:Collection与Collections区别 1.Java.until.Collection是集合接口 2.Java.until.Collections是集合工具类,方便集合的操作 二. ...
- Go-包-package-modules-import
- [转帖]Linux命令(64)——strings命令
https://cloud.tencent.com/developer/article/1414999 1.命令简介 strings命令是二进制工具集GNU Binutils的一员,用于打印文件中可打 ...
- [转帖]Nginx优化与防盗链
目录 一.配置Nginx隐藏版本号 1.第一种方法修改配置文件 2.第二种方法修改源码文件,重新编译安装 二.修改Nginx用户与组 三.配置Nginx网页缓存时间 四.实现Nginx的日志分割 五. ...
- [转帖]PostgreSQL 压测工具pgbench
1.命令 pgbench --help pgbench is a benchmarking tool for PostgreSQL. Usage: pgbench [OPTION]... [DBN ...
- 【转帖】You can now run a GPT-3-level AI model on your laptop, phone, and Raspberry Pi
https://arstechnica.com/information-technology/2023/03/you-can-now-run-a-gpt-3-level-ai-model-on-you ...
- [转帖]linux 查看CPU 内存的信息
https://bbs.huaweicloud.com/blogs/302929 [摘要] ECS信息规格:2vCPUs | 4GiB | kc1.large.2镜像:openEuler 20.0 ...
- [转帖]awk命令 去掉重复行
https://developer.aliyun.com/article/885946?spm=a2c6h.24874632.expert-profile.263.7c46cfe9h5DxWK lin ...
- Redis labs 的安装
Install and setup This guide shows how to install Redis Enterprise Software, which includes several ...
- JS 逆向之 Hook,吃着火锅唱着歌,突然就被麻匪劫了!
关注微信公众号:K哥爬虫,QQ交流群:808574309,持续分享爬虫进阶.JS/安卓逆向等技术干货! 什么是 Hook? Hook 中文译为钩子,Hook 实际上是 Windows 中提供的一种用以 ...