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 ...
随机推荐
- vue.js----之前端路由(二)
上一篇我们已经把vue框架搭好了,接下来我们进行路由模块 在src目录下新建router.js 添加如下代码 1 /** 2 * Created by sioxa on 2016/10/29 0029 ...
- kunkun
<html> <head> <title>cxk</title> </head> <body><h1>给设计师:字体 ...
- 问题:为啥explain 后type=all
最近在学习mysql 调优,学习explain执行计划,为了模拟出type=system或const,我创建了一张表test(id,name),id为主键,里面放了一条数据 执行 EXPLAIN SE ...
- 批量添加esxi主机到Vcenter
1 连接vcenter Connect-VIServer -Protocol https -User 'administrator@vsphere.local' -Password 'Vcenter密 ...
- About TopoJSON
An extension of GeoJSON that encodes topology! TopoJSON https://github.com/topojson/topojson The To ...
- CCF 201812-1 小明上学
#include <iostream> #include <bits/stdc++.h> #include <string> using namespace std ...
- 无感知WPF窗口透明加穿透
在窗口的XAML文件中添加以下属性: ShowInTaskbar="False" WindowStyle="None" AllowsTransparency=& ...
- SQL CASE 标注
根据 状态值 显示中文备注 case when a.zht='0' then '录入' when a.zht='1' then '待审核' when a.zht='2' then '已审核' end ...
- 性能测试-Jmeter无图型界面运行模式
1.Jmeter进入帮助中心 1.在机器内安装jmeter的安装bin目录内直接输入cmd,会打开dos命令行 2.再cmd里输入,jmeter --help可以查看参数说明 2.Jmeter参数说明 ...
- (原创)odoo one2many字段以子列表形式显示
模块详情