E. Permutation Game
https://codeforces.com/contest/1772/problem/E
题目大意就是给一个1~n的全排序列,所有数字都是红色的,两人轮流操作,操作有三种选择,第一是将所有蓝色的数字任意排列,第二是将其中一个红色数字变蓝,第三是什么都不操作,该游戏有三种情况1胜,2胜和平局,如果最后序列为1~n的排列形式1胜,如果为n~1的排列形式则2胜利
思路:由上面我们发现,如果出现一种情况就是还剩一个就全变蓝了,则是平局,我们可以比较1~n的全排和n~1的全排和原来的序列,得到两个人赢分别需要变蓝多少个,注意这里要区分两个人都要的需要变蓝的元素
代码
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=5e5+10;
long long p[N];
int n;
int main(){
int t;
cin>>t;
while(t--){
cin>>n;
int sum1=0,sum2=0;//统计各自需要变蓝的元素个数,不包括同时需要的
int sum=0;//统计两个人同时需要的
for(int i=1;i<=n;i++){
cin>>p[i];
if(p[i]==n-i+1&&p[i]!=i) sum1++;
if(p[i]==i&&p[i]!=n-i+1) sum2++;
if(p[i]!=i&&p[i]!=n-i+1) sum++;
}
while(sum1+sum>0||sum2+sum>0){//我们发现,如果想要赢,优先选只有自己需要的元素,再选两人都需要的元素
if(sum1>0) sum1--;
else sum--;
if(sum1+sum<=0) break;
if(sum2>0) sum2--;
else sum--;
if(sum2+sum<=0) break;
}
if(sum1+sum==0&&sum2>0) cout<<"First"<<endl;//如果第一个所需要变蓝的元素全部选完但第二个人需要的还没选完
else if(sum2+sum==0&&sum1>0) cout<<"Second"<<endl;//第二个同上
else cout<<"Tie"<<endl;//如果没人多余的话,说明其中最后一个是两人都需要选的,则谁先选谁就输,因此两人都会跳过形成死循环
}
}
E. Permutation Game的更多相关文章
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Next Permutation 下一个排列
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- Leetcode 60. Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- UVA11525 Permutation[康托展开 树状数组求第k小值]
UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...
- Permutation test: p, CI, CI of P 置换检验相关统计量的计算
For research purpose, I've read a lot materials on permutation test issue. Here is a summary. Should ...
- Permutation
(M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II
- Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
随机推荐
- MATH1851 Trigonometric Formula Notes
大学里老师都默认我们学过 正割 \(\sec\),余割 \(\csc\) 与余切 \(\cot\) 再加上高中的一些公式都有点遗忘,开个贴做个笔记 常规的 \(\sin x, \cos x, \tan ...
- Nextcloud报 PHP zip 模块未安装
wget https://pecl.php.net/get/zip自动下载最新包 tar xf zip-1.20.0.tgz cd zip-1.20.0/ phpize 报错system libzip ...
- 如何修改驱动使得NVIDIA Geforce GTX 970, 980, 980 TI and Titan X等显卡可以在Win XP/Win 2003 server x64下驱动?
感谢Matt,一个老外,非常好的修改方法. 本人亲测成功. I recently built a new computer to better accommodate the forthcoming ...
- 一、100ASK_IMX6ULL嵌入式裸板学习_LED实验(知识点补充二)
MUX是什么? MUX(multiplexer数据选择器): 在多路数据传送过程中,能够根据需要将其中任意一路选出来的电路,叫做数据选择器,也称多路选择器或多路开关. 多路转换器的作用主要 ...
- WPF 使用Path(自定义控件,圆形进度条)
原文:https://www.cnblogs.com/tsliwei/p/5609035.html 原文链接:https://blog.csdn.net/johnsuna/article/detail ...
- 【React】React项目实践中的问题
报错'react-scripts' 不是内部或外部命令,也不是可运行的程序 React新建脚手架项目,在目录下添加了public\index.html,src\App.js,index.js文件,除此 ...
- react hooks组件父组件调用子组件方法
函数组件父组件调用子组件方法需要使用 useImperativeHandle 和 forwardRef 两个方法 1.子组件 2.父组件 注意:一定要使用ref来接从子组件传过来的实例值,用其他的在函 ...
- [转载] Image Pixels
转载自http://shutha.org/node/789 Image Pixels Pictures that are printed or that are displayed on a di ...
- MySQL 学习(四)并集查询
联合查询,它是用 union 关键字把多条 select 语句的查询结果合并为一个结果集.纵向合并的前提是被合并的结果集的字段数量.顺序和数据类型必须完全一致.字段名不一样的情况下,会将第一个结果集的 ...
- 嵌入式Linux应用开发
3-4 Makefile常用的函数 i. $(foreach var,list,text) 简单地说,就是 for each var in list, change it to text. 对lis ...