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 ...
随机推荐
- python下载站长素材免费简历模板(xpath)
import os.path import requests from lxml import etree if __name__ == '__main__': if not os.path.exis ...
- pycharm字体大小设置
首先有两个方法 一个是滚轮放大缩小,一个是固定的字体大小. 调为固定的字体大小: 菜单栏:file--setting--editor--font--size 修改为需要大小字号,例如20,点击ok 滚 ...
- fread()函数读文本文件重复读最后一个字符问题【已解决】
对文本文件读写时遇到一个问题,fread()读所有内容的时候文件的最后一个字符总会重复读,我的代码如下: FILE* file = nullptr; fopen_s(&file, " ...
- CSP202104-4 校门外的树
设状态时,首先从简单状态设起: 一维不行再试二维.简单状态应付不了再设复杂的(因为某些状态可以体现在状态转移的过程中,或者说状态转移方程中,不一定体现在原式中) E.g. 计算机软件能力认证考试系统- ...
- python+接口参数化(ddt和pytest.mark.parametrize())使用
一.ddt(基于unittest) 实例:字典解包[{},{}] test_data=t.read_excel(mode,case_list)@ddt class Interface(unittest ...
- 日志分析查看—— cat+grep+awk+uniq+sort+wc+join
有个统计日志信息的需求,下面是使用到的命令 //按 \t 对文件每一行进行切割,正则匹配第二列为32896时,输出第一列:再进行排序并去重,最后统计行数 cat file.log|awk -F '\t ...
- 25_Webapck原理
Webpack源代码解析 webpack其实也就是一个函数的调用,返回一个Compile的对象,再调用Compile的run方法就可以完成项目的构建 那么我们肯定是先要从webpack这个函数去理解它 ...
- 002 jmeter入门级写脚本及参数化
1.jmeter入门脚本 步骤分析:测试计划(项目名称)-线程组(业务流程)-http请求(接口名称)-察看结果树 编写脚本四要素:测试计划.至少有一个线程组.至少有一个取样器.必须要有监听器 测试计 ...
- GoLand 和 Pycharm的 快捷键设置与常用插件
GoLand 插件 Gopher 美化进度条,让等待更优雅. CodeGlance pro 旁边浏览框. 快捷键设置 删除行: ctrl + L 重新格式化代码 ctrl + K 开始新行 ctrl ...
- 【java】MVC模式和三层架构
MVC是一种分层开发的模式 M:Model,业务模型,处理业务,存储数据,获取数据.JavaBean对象 V: View , 视图,界面展示,展示数据.JSP或HTML C: Controller, ...