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. kafka数据顺序一致

    问题: kafka如何发送顺序消息 方案:kafka可以通过partitionKey,将某类消息写入同一个partition,一个partition只能对应一个消费线程,以保证数据有序. 也就是说生产 ...

  2. nodejs mongoose连接mongodb报错,command find requires authentication

    MongoError: command find requires authentication at Connection.<anonymous> (/home/Map/node_mod ...

  3. ARM的发展史以及架构解析

    本文从ARM的发展历史着手,以S3C2440为例与51单片机进行对比分析,详细解析了ARM架构. 先来谈一下ARM的发展史:1978年12月5日,物理学家Hermann Hauser和工程师Chris ...

  4. 用requests-html和SelectorGadget轻松精准抓取网页数据

    我们在抓取网页数据时,最常採用Python的requests搭配BeautifulSoup的模式来完成.然而,requests-html整合了上述2个套件,又添加了新的功能,或许是抓取网页数据值得考虑 ...

  5. redis的linux下安装

    Linux 源码安装 下载地址:http://redis.io/download,下载最新稳定版本. 本教程使用的最新文档版本为 2.8.17,下载并安装: # wget http://downloa ...

  6. Generative Adversarial Network - Python实现

    算法特征 ①. discriminator区别真假; ②. generator以假乱真 算法推导 Part Ⅰ: 熵之相关定义 entropy之定义如下, \[\begin{equation*} H( ...

  7. CamstarVP表格删除行报错

    前提:是从服务中拖出来的表格,带表达式的.但是点击删除按钮的时候,直接页面报错. 原因是:VP上面没有指定服务.

  8. LeNet,AlexNet,VGG,GoogLeNet

    卷积神经网络-LeNet 理解channel:卷积操作完成后输出的 out_channels ,取决于卷积核的数量.此时的 out_channels 也会作为下一次卷积时的卷积核的 in_channe ...

  9. Laravel 5.1 LTS 速查表

    https://cs.laravel-china.org/# Artisan // 在版本 5.1.11 新添加,见 http://d.laravel-china.org/docs/5.1/autho ...

  10. 三.database阶段回顾

    阶段回顾: 1.mysql:文件管理软件 2.三部分: 服务端 sql语句 客户端 3.客户端 mysql navicat 4.授权操作 用户操作 授权操作 5.sql语句 数据库操作 create ...