https://codeforces.com/contest/1772/problem/E

题目大意就是给一个1~n的全排序列,所有数字都是红色的,两人轮流操作,操作有三种选择,第一是将所有蓝色的数字任意排列,第二是将其中一个红色数字变蓝,第三是什么都不操作,该游戏有三种情况1胜,2胜和平局,如果最后序列为1~n的排列形式1胜,如果为n~1的排列形式则2胜利

思路:由上面我们发现,如果出现一种情况就是还剩一个就全变蓝了,则是平局,我们可以比较1~n的全排和n~1的全排和原来的序列,得到两个人赢分别需要变蓝多少个,注意这里要区分两个人都要的需要变蓝的元素

代码

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. using namespace std;
  5. const int N=5e5+10;
  6. long long p[N];
  7. int n;
  8. int main(){
  9. int t;
  10. cin>>t;
  11. while(t--){
  12. cin>>n;
  13. int sum1=0,sum2=0;//统计各自需要变蓝的元素个数,不包括同时需要的
  14. int sum=0;//统计两个人同时需要的
  15. for(int i=1;i<=n;i++){
  16. cin>>p[i];
  17. if(p[i]==n-i+1&&p[i]!=i) sum1++;
  18. if(p[i]==i&&p[i]!=n-i+1) sum2++;
  19. if(p[i]!=i&&p[i]!=n-i+1) sum++;
  20. }
  21. while(sum1+sum>0||sum2+sum>0){//我们发现,如果想要赢,优先选只有自己需要的元素,再选两人都需要的元素
  22. if(sum1>0) sum1--;
  23. else sum--;
  24. if(sum1+sum<=0) break;
  25. if(sum2>0) sum2--;
  26. else sum--;
  27. if(sum2+sum<=0) break;
  28. }
  29. if(sum1+sum==0&&sum2>0) cout<<"First"<<endl;//如果第一个所需要变蓝的元素全部选完但第二个人需要的还没选完
  30. else if(sum2+sum==0&&sum1>0) cout<<"Second"<<endl;//第二个同上
  31. else cout<<"Tie"<<endl;//如果没人多余的话,说明其中最后一个是两人都需要选的,则谁先选谁就输,因此两人都会跳过形成死循环
  32. }
  33. }

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. Django里ORM常用关键字

    一.ORM常用关键字 # 关键概览 1.create() 2.filter() 3.first() last() 4.update() 5.delete() 6.all() 7.values() 8. ...

  2. 实验:两片ESP8266,分别做客户端和服务器,实现双向收发数据

    手机做热点: 每片都做STATION

  3. 第七章用Python实现对Excel文件中的数据进行md5加密

    文章目录 获取数据 加密函数 数据加密 结尾 源码地址 本文可以学习到以下内容: 使用 pandas 中的 to_excel 生成 excel 数据 使用 pandas 中的 read_excel 读 ...

  4. JQuery 的$.each取值

    原文:https://www.cnblogs.com/zhaixr/p/7069857.html 1.遍历一维数组 var arr1=['aa','bb','cc','dd']; $.each(arr ...

  5. 固定代码格式化程序插件-Prettier JetBrains

    基本使用 使用npm install prettier --save-dev为您的项目添加更漂亮或全局安装 使用Prettier选择要格式化的代码或文件 使用"Reformat with P ...

  6. c语言中printf不输出任何东西?,缓冲区未满不输出任何东西

    下面代码为什么没有任何输出: #include<cstdio> #include<unistd.h> int main(int argc, char **argv){ whil ...

  7. win10 U盘重装系统

    1.做好U盘 2.F7选择U盘启动,不用F2切换启动顺序 3.IQY一键安装 4.重启前拔掉U盘 5.如果重启后蓝屏显示 恢复,重新进入PE使用 windows引导恢复,再重新启动

  8. const char* str和const char str[]的区别

    首先,字符串常量是存储在flash中的.假设字符串常量在flash中的地址是0x8003fb8. 第一种方式,str等价于str的内存单元的地址,str的内存单元存储着字符串常量的地址 第二种方式,s ...

  9. docker 安装 elasticsearch7.6.2 kibana7.6.2

    [root@abcdefg bin]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6896f6e3202c ...

  10. UI动画练习 - CABasicAnimation:视图绕X/Y轴旋转(3D效果)

    视图 3D 旋转 1 - 代码示例:以绕 X 轴旋转为例 1 #import "ViewController.h" 2 @interface ViewController () 3 ...