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

  1. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  2. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  5. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  6. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  7. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

  10. AtCoder Beginner Contest 075 C bridge【图论求桥】

    AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...

随机推荐

  1. hbck2的一些用法

    一.执行 hbase org.apache.hbase.HBCK2 可以看到下面一些选择项 **示例: -d 打印debug日志 -s 跳过客户端与服务端一致性的版本检测 hbase org.apac ...

  2. 开启IPV6网络

    1.路由器开启IPV6支持 2.路由器关闭IPV6 DHCP服务 3.若外网无法访问则关闭路由器防火墙 或关闭系统防火墙 4.tomcat需设置地址为0.0.0.0

  3. Java 将Markdown文件转换为Word和PDF文档

    Markdown 凭借其简洁易用的特性,成为创建和编辑纯文本文档的常用选择.但某些时候我们需要更加精致的展示效果,例如在专业分享文档或打印成离线使用的纸质版时,就需要将Markdown文件以其他固定的 ...

  4. Node.js中的模块

    CommonJS模块 CommonJS是一种规范,它定义了JavaScript 在服务端运行所必备的基础能力,比如:模块化.IO.进程管理等.其中,模块化方案影响深远,其对模块的定义如下: 1,模块引 ...

  5. Spring手动获取bean的四种方式

    一.实现BeanFactoryPostProcessor接口 @Component public class SpringUtil implements BeanFactoryPostProcesso ...

  6. Java 反射获取对象里的值

    最近在负责邮件服务,里面会涉及到很多Email模板,这里我使用到了java的模板引擎:jetbrick-template,需要使用Map集合一个个往里面设置值,然后调用模板方法,进行替换.实体类一个个 ...

  7. HTB- Archetype

    端口扫描 nmap -sV -sT 10.129.1.1 smbclint smbclient -L 10.129.149.214 获取密码 smbclient //10.129.149.214/ba ...

  8. Solo 开发者周刊 (第8期):Claude公司再度上新产品,成交额将超73亿美元

    这里会整合 Solo 社区每周推广内容.产品模块或活动投稿,每周五发布.在这期周刊中,我们将深入探讨开源软件产品的开发旅程,分享来自一线独立开发者的经验和见解.本杂志开源,欢迎投稿. 好文推荐 Cla ...

  9. Mysql-explain之Using temporary和Using filesort解决方案

    第一条语句 explainselect * from tb_wm_shop where is_delete != 1 and is_authentication = 1 ORDER BY create ...

  10. 输入Javac提示不是内部或外部命令

    先去百度搜索"jdk下载"下载最新版jdk,并安装,安装目录不用去更改,直接默认就好,下载完了之后,双击打开安装,jdk安装完成后,会接着安装jre包,(jre和jdk是配对的,不 ...