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. java 注解基础

    java 内置注解 注解 作用 描述 @Override 将覆盖父类中的方法 作用在子类的方法上 @Deprecated 代码被弃用 使用了被@Deprecated注解的代码则编译器将发出警告 @Su ...

  2. nacos服务端和客户端版本不一致的时候,客户端无限刷日志

    解决方法: logging: level: com: alibaba: nacos: client: error

  3. java.net.ConnectException: Your endpoint configuration is wrong; For more details see: http://wiki.apache.org/hadoop/UnsetHostnameOrPort

    今天使用在hive中建表,并在hive中将查询到的语句插入到新表中时,一直开在如图所示位置不动 等待了20多分钟,然后报了这么个错 java.net.ConnectException: Your en ...

  4. C# 读取串口设备列表

    ManagementObjectSearcher 解析不到头文件,需要手动 Add Referance 需要添加引用:System.Management,然后引入命名空间:using System.M ...

  5. HJ92 在字符串中找出连续最长的数字串

    描述 输入一个字符串,返回其最长的数字子串,以及其长度.若有多个最长的数字子串,则将它们全部输出(按原字符串的相对位置) 本题含有多组样例输入. 输入描述: 输入一个字符串. 输出描述: 输出字符串中 ...

  6. Kubernetes--Pod存活性探测(设置exec探针)

    有不少应用程序长时间持续运行后会逐渐转为不可用状态,并且仅能通过重启操作恢复,Kubernetes的容器存货性探测机制可发现诸如此类的问题,并根据探测结果结合重启策略触发后续的行为.存活性探测是隶属于 ...

  7. react native 状态栏和安全区域的使用

    1.  状态栏组件,react native文档提供了说明.我需要的是设置透明效果,如下图. 代码如下 <StatusBar translucent={true} backgroundColor ...

  8. 记录multipartFile表单类型转化为file

    导入依赖 <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</a ...

  9. 自己写的java教程,免费分享

    自己写的一套java教程,主要用于内部培训使用,有需要的可以直接免费下载: http://it.zhenzikj.com/download/java.zip 一共写了3套: java语言基础.网络开发 ...

  10. 【rocky linux】firewalld切换到iptables 以及Failed to start IPv4 firewall with iptables.

    关闭[firewalld],安装iptables并启动 #关闭自带 firewall systemctl stop firewalld systemctl mask firewalld#显示当前 fi ...