AtCoder Beginner Contest 313
AtCoder Beginner Contest 313 - AtCoder
A - To Be Saikyo (atcoder.jp)
从\(a_1 \dots a_{n-1}\)找出最大值与\(a_0\)比较即可
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> A(n);
for(auto &i : A) cin >> i;
int ma = *max_element(A.begin() + 1, A.end());
cout << max(ma - A[0] + 1, 0ll) << endl;
return 0;
}
B - Who is Saikyo? (atcoder.jp)
每次将能力更弱的去掉,看最后是否还剩一个最强的
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin >> N >> M;
set<int> A;
for(int i = 1;i <= N;i ++)
A.insert(i);
for(int i = 0;i < M;i ++){
int x,y;
cin >> x >> y;
A.erase(y);
}
if(A.size() == 1)
cout << *A.begin() << endl;
else
cout << "-1\n";
return 0;
}
C - Approximate Equalization 2 (atcoder.jp)
因为可以用大的去补小的,所以都往中间靠,要计算小于平均数的差多少到平均数,将这些分配好后,如果还有还有大于平均数+1的,还要继续分配,\(sum\bmod n\)就是计算多出来的,另外那些本身大于平均数的数只要减到比平均数多1即可,不用完全减到和平均数相等
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> A(N + 1);
int sum = 0;
for(int i = 1;i <= N;i ++){
cin >> A[i];
sum += A[i];
}
int ans = 0,num = 0, tag = sum / N;
for(int i = 1;i <= N;i ++){
ans += max(tag - A[i], 0ll);
num += (A[i] > tag);
}
cout << ans + max(sum % N - num,0ll) << endl;
return 0;
}
D - Odd or Even (atcoder.jp)(交互题)
因为原数组仅由\(0,1\)构成,并且每次询问后\(a_1 + a_2 + \dots +a_k\)的和的奇偶性也是用\(01\)表示,所以我们可以把和当作$a_1 \oplus a_2 \oplus \dots \oplus a_k $的值.
当\(n=4,k=3\)时,我们可以询问1 2 3 ,1 2 4, 1 3 4 ,将三个结果的值异或之后就是\(a_1\)的值.
三个结果异或即:
\(res_1 \oplus res_2 \oplus res_3 = a_1 \oplus a_2 \oplus a_3 \oplus a_1 \oplus a_2 \oplus a_4 \oplus a_1 \oplus a_3 \oplus a_4\)
根据异或的性质,一个数异或自身偶数次等于\(0\),而0异或其他数等于其他数,所以上式的值就等于\(a_1\).
同理,如果再询问2 3 4,结合1 2 3,1 2 4,我们可以得到\(a_2\)的值.
由此我们对前\(k+1\)个数进行询问就能得到前\(k+1\)个数的值,那怎么得到\(k+2\)之后的值呢?
我们可以询问\(3,4 \dots k+1,k+2\)的结果,即\(a_3 \oplus a_4 \dots a_{k+1} \oplus a_{k+2}\)的值,且前面\(a_3 \sim a_{k+1}\)我们都已经知道了,那把前面这个\(res\)去异或上它们不就得到\(a_{k+2}\)的值了吗.
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector<int> ans(N);
auto solve = [&]() {
vector<int> T(K + 1);
vector<int> Q;
for (int i = 0; i <= K; i ++) {
Q.clear();
for (int j = 0; j <= K; j ++)
if (j != i)
Q.emplace_back(j);
cout << '?';
for (auto j : Q)
cout << ' ' << j + 1 ;
cout << endl;
cin >> T[i];
}
for (int i = 0; i <= K; i ++)
for (int j = 0; j <= K; j ++)
if (j != i)
ans[i] ^= T[j];
};
solve();
for (int i = K + 1; i < N; i ++) {
cout << '?';
for (int j = i; j > i - K; j--)
cout << ' ' << j + 1;
cout << endl;
cin >> ans[i];
for (int j = i - 1; j > i - K; j --)
ans[i] ^= ans[j];
}
cout << '!';
for (auto i : ans)
cout << ' ' << i;
cout << endl;
return 0;
}
AtCoder Beginner Contest 313的更多相关文章
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】
AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...
- AtCoder Beginner Contest 075 C bridge【图论求桥】
AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...
随机推荐
- Scrapy爬取知名技术文章网站
scrapy安装以及目录结构介绍 创建有python3的虚拟环境 mkvirtualenv mkvirtualenv py3env 安装scrapy 进入虚拟环境py3env,把pip的源设置为豆瓣源 ...
- 解析下载blob视频
前言 浏览器中有些视频是通过blob:https://baike.baidu.com/bf834217-9442-4c98-9ef6-0bd5f3408a4e的形式给出的.blob后面的网址不能直接访 ...
- 免费的Java主流jdk发行版本有哪些?
Java的特点是百花齐放,不像c#或者go只有一家主导.oracle jdk收费了,没关系,不是只有它可用.java还有很多免费的主流的jdk发行版本,记录下来备忘. OpenJDK - 官方网站 - ...
- 【动手学深度学习】第五章笔记:层与块、参数管理、自定义层、读写文件、GPU
为了更好的阅读体验,请点击这里 由于本章内容比较少且以后很显然会经常回来翻,因此会写得比较详细. 5.1 层和块 事实证明,研究讨论"比单个层大"但"比整个模型小&quo ...
- ecnuoj 5039 摇钱树
5039. 摇钱树 题目链接:5039. 摇钱树 感觉在赛中的时候,完全没有考虑分数规划这种做法.同时也没有想到怎么拆这两个交和并的式子.有点难受-- 当出现分数使其尽量大或者小,并且如果修改其中直接 ...
- B码对时方案,基于TI AM62x异构多核工业处理器实现!
什么是IRIG-B码对时 IRIG-B(inter-range instrumentationgroup-B)码是一种时间同步标准,通常用于精确的时间测量和数据同步,广泛应用于电力.通信.航空等领域. ...
- PHP转Go系列 | ThinkPHP与Gin框架之API接口签名设计实践
大家好,我是码农先森. 回想起以前用模版渲染数据的岁月,那时都没有 API 接口开发的概念.PHP 服务端和前端 HTML.CSS.JS 代码混合式开发,也不分前端.后端程序员,大家都是全干工程师.随 ...
- 【PHP】关于fastadmin框架中使用with进行连表查询时setEagerlyType字段的理解
前言 FastAdmin是我第一个接触的后台管理系统框架.FastAdmin是一款开源且免费商用的后台开发框架,它基于ThinkPHP和Bootstrap两大主流技术构建的极速后台开发框架,它有着非常 ...
- [oeasy]python001_先跑起来_python_三大系统选择_windows_mac_linux
先跑起来 Python 什么是 Python? Python [ˈpaɪθɑ:n] 是 一门 适合初学者 的编程语言 添加图片注释,不超过 140 字(可选) 类库 众多 几行代码 就 ...
- Django 继承AbstractUser扩展用户模型
Django 继承AbstractUser扩展用户模型 by:授客 QQ:1033553122 测试环境 Win 10 Python 3.5.4 Django-2.0.13.tar.gz 官方 ...