Codeforces 1404 D. Game of Pairs
Codeforces 1404 D.Game of Pairs
给定\(2n\)个数\(1,2,...,2n\),A 和 B 将进行交互,规则如下:
- A 需要将元素分成 n 组 \(\mathbf{pair}\)(二元组)
- B 从每组 \(\mathbf{pair}\)中选择一个元素,如果权值和是 \(2n\) 的倍数,那么 B 胜,否则 A 胜。
你需要选择 A/B 中的一者扮演角色,并取得胜利。
\(n\le 5\times 10^5\).
老子懒得讲了,你们TMD对着代码自己发愣去吧。
由于可以自选角色,所以我们分别考虑两个角色的必胜情况。
考虑A,我们首先发现如下性质:
- 由于\(\sum\limits_{i=1}^n=\frac{n\times(n-1)}{2}\),所以当\(n\)是偶数时,\(\sum_{i=1}^n\)一定不是\(n\)的倍数。
于是针对n为偶数的情况我们可以很容易地构造出无解的方案:将\(i\)和\(i+n(i\in[1,n])\)放进一组,那么无论B怎么选,最后的总和一定是形如\(\frac{n\times(n-1)}{2}+kn\)的某个数,这个式子的后一项一定是n的倍数,而前一项一定不是n的倍数,所以A必胜。
那么我们继续考虑n为奇数的情况。
然而遗憾的是,这种情况下,B是存在必胜策略的...
考虑B,我们重新审视A中发现的性质:
- 由于\(\sum\limits_{i=1}^{n}=\frac{n\times(n-1)}{2}\),所以当n是奇数是,\(\sum_{i=1}^{n}\)一定是n的倍数。
然后如何取这个方法实在是抽象,难以描述,所以
非常抱歉,这篇文章从这里开始又咕了。
code:
#include<bits/stdc++.h>
using namespace std;
const int maxn=500005;
int n,fa[maxn<<1],siz[maxn<<1];
int tp[maxn<<1],xorv[maxn<<1],used[maxn<<1];
int Q[maxn],topc;
bool vis[maxn<<1];
inline int read(){
int res=0,f_f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f_f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)+(ch-'0'),ch=getchar();
return res*f_f;
}
inline int get_fa(int x){
return x==fa[x]?x:fa[x]=get_fa(fa[x]);
}
inline void merge_fa(int x,int y){
siz[get_fa(x)]+=siz[get_fa(y)];
fa[get_fa(y)]=get_fa(x);
}
inline void dfs(int u){
vis[u]=true;
int v=xorv[tp[u]]^u;
v=(v>n)?v-n:v+n;
if(vis[v]) return;
merge_fa(u,v),dfs(v);
}
int main(){
n=read();
if(n%2==0){
printf("First\n");
cout.flush();
for (int i=1;i<=(n<<1);i++){
if(i^(n<<1)) printf("%d ",(i-1)%n+1);
else printf("%d\n",(i-1)%n+1);
cout.flush();
}
}
else{
printf("Second\n");
cout.flush();
for (int i=1;i<=(n<<1);i++) tp[i]=read(),xorv[tp[i]]^=i;
for (int i=1;i<=(n<<1);i++) fa[i]=i;
for (int i=n+1;i<=(n<<1);i++) siz[i]=1;
for (int i=1;i<=(n<<1);i++){
if(vis[i]) continue;
dfs(i);
}
int ans=(n+1)/2&1;
for (int i=1;i<=(n<<1);i++){
if(i^get_fa(i)) continue;
int v=get_fa(xorv[tp[i]]^i);
if(v>i) continue;
used[i]=1,ans^=(siz[i]&1);
}
if(ans){
for (int i=1;i<=(n<<1);i++){
if(!used[i]) continue;
int v=get_fa(xorv[tp[i]]^i);
if((siz[v]^siz[i])&1){
used[i]=0,used[v]=1;
break;
}
}
}
for (int i=1;i<=(n<<1);i++){
if(used[get_fa(i)]) Q[++topc]=i;
}
for (int i=1;i<=topc;i++){
if(i^topc) printf("%d ",Q[i]);
else printf("%d\n",Q[i]);
}
}
return 0;
}
Codeforces 1404 D. Game of Pairs的更多相关文章
- Educational Codeforces Round 10 C. Foe Pairs 水题
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...
- Codeforces Round #562 (Div. 2) B. Pairs
链接:https://codeforces.com/contest/1169/problem/B 题意: Toad Ivan has mm pairs of integers, each intege ...
- Codeforces 159D Palindrome pairs
http://codeforces.com/problemset/problem/159/D 题目大意: 给出一个字符串,求取这个字符串中互相不覆盖的两个回文子串的对数. 思路:num[i]代表左端点 ...
- codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)
题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- codeforces#572Div2 E---Count Pairs【数学】【同余】
题目:http://codeforces.com/contest/1189/problem/E 题意:给定$n$个互不相同数,一个$k$和一个质数$p$.问这$n$个数中有多少对数$(a_i+a_j) ...
- CodeForces - 1189E Count Pairs(平方差)
Count Pairs You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Fi ...
- Codeforces 1169B Pairs
题目链接:http://codeforces.com/contest/1169/problem/B 题意:给你 m 对数 ,问你能不能在 1 − n 之间找到俩个不相等的 x 和 y 使得 对于前面每 ...
- CodeForces - 1189 E.Count Pairs (数学)
You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Find the numbe ...
- Codeforces 1188B - Count Pairs(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...
随机推荐
- 如何学习iOS开发?iOS Developer Library足矣!
记得上高中的时候,寄信请教二哥学习经验,二哥来信介绍学习经验说:资料书要快速阅读,把书上的题做完,然后再买几套资料书(习题集)继续练习. 这是二哥的经验,因为他自学能力强,可以消化多套资料书. 我仿照 ...
- DOS批处理中%cd%与%~dp0的区别详解
转载:https://www.jb51.net/article/105325.htm DOS批处理中%cd%与%~dp0的区别详解 Windows下批处理中%cd%和%~dp0都能用来表示当前 ...
- Inno Setup 5打包exe遇到的坑,做一个学习记录
; 脚本由 Inno Setup 脚本向导 生成!; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "人员管理系统"#de ...
- 多测师讲解python _类(原始版)_高级讲师肖sir
# Python中的类: '''定义一个类:class +名称=类 在类当中定义:def +名称=实例方法(self)与类平齐def +名称=普通函数定义一个函数:def +名称=函数在函数中:函数( ...
- 工业级wifi模块
工业级wifi模块 工业级wifi模块ZLSN7004是上海卓岚开发的一款高性能的Wifi.以太网转串口模块.与普通的wifi模块定位在低成本不同,7004定位在高稳定性.丰富功能,设计目标是面向对功 ...
- Navicat Premium 15破解
https://pan.baidu.com/s/1bJ1BJUcL6cFd4StB5Qn_hQ 提取码:1314 拿走,不谢!!!
- python爬虫 -掘金
import json from time import sleep import requests url = "https://web-api.juejin.im/query" ...
- 第十三章 Linux三剑客之老二—sed
一.sed #擅长增删改查 替换 选项: -n #取消默认输出 -r #支持扩展正则使用 -i #改变文件内容 -e #允许多项编辑 内部指令: p #print 打印 d # 删除 排除 a ...
- ffmpeg+Python实现B站MP4格式音频与视频的合并
目录 安装 官网下载 环境变量 验证 ffmpeg的使用 Python实现自动处理 文件结构 番剧缓存结构 常规缓存结构 文件信息 代码 具体代码 代码说明 安装 官网下载 http://ffmpeg ...
- 你真的了解Python吗?这篇文章可以让你了解90%
人们为什么使用Python? 之所以选择Python的主要因素有以下几个方面: 软件质量:在很大程度上,Python更注重可读性.一致性和软件质量,从而与脚本语言世界中的其他工具区别开发.此外,Pyt ...