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

  1. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  2. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  3. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  4. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  6. 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 ...

  7. UVA11525 Permutation[康托展开 树状数组求第k小值]

    UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...

  8. 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 ...

  9. Permutation

    (M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II

  10. Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

随机推荐

  1. PDF.JS 预览pdf文件,中文不显示问题

    pdf.js 下载路径 http://mozilla.github.io/pdf.js/ pdf.js的使用不多说,网上都有 讲一下,.NET CORE MVC的使用遇到的问题 1. 将下载文件解压放 ...

  2. memoの左手转右手

    说的是坐标系. 假设两个坐标系都是X向右,Y向上.那么,右手系的Z是从屏幕垂直向外,左手系的Z就是垂直屏幕向里. 向量假设是列向量.(OpenGL系的毛病啊,列向量,右手系,泪目) 先说结论 变换矩阵 ...

  3. FSL--fsleyes建立软连接方法

    在使用conda下载完fsleyes后,还是显示not found ,无法使用怎么办? 1.首先在/anaconda/envs/fslpython/bin/  中搜索 fsleyes  确定已经下载好 ...

  4. 微信支付模式二java

    这个星期写了下微信支付模式二,在这里进行下整理 微信支付官方文档 1. 需要的配置..具体看下面的链接. https://pay.weixin.qq.com/wiki/doc/api/native.p ...

  5. Linux 第七节( 磁盘配额,RAID )

    vim /etc/fstab    //编辑文件 UUID=xxxxxxxxxxxxxx /boot xfs defaults,uquota 0 0    //增加uqota命令,允许磁盘扩容 ino ...

  6. flutter tabbar指示器indicator宽度高度自定义

    在tabbar中indicator宽度是无法修改的,所以需要咱们去自定义indicator. 下面是自定义的代码,直接拷贝使用,已做好修改. // Copyright 2018 The Chromiu ...

  7. VM虚拟机15安装Kali Linux2020版详细教程

    下载kali镜像 kali Linux官网地址https://www.kali.org/downloads/下载相对应的电脑版本 打开Vmware虚拟机 安装虚拟机看物理机配置,尽量不要太折腾电脑(虚 ...

  8. pytest(5)-自定义用例顺序(pytest-ordering)-后续学习

    前言 测试用例在设计的时候,我们一般要求不要有先后顺序,用例是可以打乱了执行的,这样才能达到测试的效果. 有些同学在写用例的时候,用例写了先后顺序, 有先后顺序后,后面还会有新的问题(如:上个用例返回 ...

  9. vue学习之-----组件递归调用

    1.关键点 2.父组件 <template> <div> <div class="btn-title"> <el-button @clic ...

  10. git 提示 fatal: Authentication failed for....

    在我们进行clone 或 pull 或 push的时候,出现这个问题,先想一下是不是自己的账号密码是不是改了 一般情况下通常需要重新重置一下验证设置 执行以下命令: git config --syst ...