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 ...
随机推荐
- Linux系统Shell脚本第六章:文件三剑客之sed
Shell编程三剑客之sed 前言 一.Sed编辑器 (1)Sed概述 (2)Sed工作流程 (3)Sed基本语法 二.Sed用法示例 (1)Sed输出指定行 (2)插入符合条件的行 (3)删除符合条 ...
- 01爬取豆瓣网电影数据进行numpy的练习
level 2:10.案例:编写爬虫爬取豆瓣电影排行榜(电影名称,评分),保存为csv文件 a.用numpy加载csv数据 b.把评分列转换成float64类型 c.计算电影的平均评分 d.求评分最高 ...
- Mac上好用的app们
记录下自己在mac上用的一些很不错的app,大多免费. 排名随缘. 不定期更新. Amphetamine 来源 AppStore 说明 欢迎使用Amphetamine,一款为macOS打造的最棒的防睡 ...
- nodejs mongoose连接mongodb报错,command find requires authentication
MongoError: command find requires authentication at Connection.<anonymous> (/home/Map/node_mod ...
- NSA对下一代新技术的评估“网络透视”2010
时间线回到2010年,那时候做渗透测试流行找目标还是通过Google hack,Google dork去寻找目标比如inurl:asp?id= 寻找asp网站可利用的注入点,在厉害点一键爬取域名在配合 ...
- SQL面试题,工作整理sql
一.数据库和算法 表名:student,name,course,score 张青 语文 72 王华 数学72 张华 英语 81 张青 物理 671.用sql查询出& ...
- java常用开发学习网站列表
持续更新中 kettle国内镜像下载 版本 地址 7.1版本 http://mirror.bit.edu.cn/pentaho/Data%20Integration/ 8.2版本 http://mir ...
- Day_1(并查集朋友圈、字典序排序)
1.并查集 朋友圈:找出最多的一个圈子内有多少用户! id[](表示当前节点的父节点) nodeNum[] (表示当前节点为根的那一组节点数量) import java.util.Scanner; / ...
- VMware导入ovf报错
如下图所示报错 在网上查找了一些解决方案,大都说是ovftool版本兼容问题,但是我这里好像并不行,最后的解决的办法是对导入的位置默认不做改动. 报错原因:改变了默认路径.
- Linux命令 日记
命令 作用 备注 pwd 查看当前所在位置 Windows和虚拟机共享文件夹路径: cd / 打开根目录 cd /mnt/hgfs/ 共享文件夹位置路径