【Codeforces 986B】Petr and Permutations
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
n为奇数时3n和7n+1奇偶性不同
n为偶数时也是如此
然后交换任意一对数
逆序对的对数的奇偶性会发生改变一次
求出逆序对 对n讨论得出答案。
【代码】
import java.io.*;
import java.util.*;public class Main {static InputReader in;static PrintWriter out;public static void main(String[] args) throws IOException{//InputStream ins = new FileInputStream("E:\\rush.txt");InputStream ins = System.in;in = new InputReader(ins);out = new PrintWriter(System.out);//code start from herenew Task().solve(in, out);out.close();}static int N = (int)1e6;static class Task{int n;int a[] = new int[N+10];int temp[] = new int[N+10];int ans = 0;public void mergesort(int l,int r) {if (l>=r) return;int mid = (l+r)/2;mergesort(l,mid);mergesort(mid+1,r);int k = l,i = l,j = mid+1;while (i <= mid && j <= r) {if (a[i]>a[j]) {ans = ans + mid-i+1;ans = ans % 2;temp[k++] = a[j];j++;}else {temp[k++] = a[i];i++;}}while (i<=mid) {temp[k++] = a[i];i++;}while (j<=r) {temp[k++] = a[j];j++;}for (i = l;i <= r;i++) a[i] = temp[i];}public void solve(InputReader in,PrintWriter out) {n = in.nextInt();for (int i = 1;i <= n;i++) {a[i] = in.nextInt();}mergesort(1,n);if (n%2==1) {if (ans==1) {out.println("Petr");}else {out.println("Um_nik");}}else {if (ans==1) {out.println("Um_nik");}else {out.println("Petr");}}}}static class InputReader{public BufferedReader br;public StringTokenizer tokenizer;public InputReader(InputStream ins) {br = new BufferedReader(new InputStreamReader(ins));tokenizer = null;}public String next(){while (tokenizer==null || !tokenizer.hasMoreTokens()) {try {tokenizer = new StringTokenizer(br.readLine());}catch(IOException e) {throw new RuntimeException(e);}}return tokenizer.nextToken();}public int nextInt() {return Integer.parseInt(next());}}
}
转载于:https://www.cnblogs.com/AWCXV/p/10498811.html
【Codeforces 986B】Petr and Permutations相关推荐
- 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)
题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...
- 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)
题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...
- 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)
题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...
- 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)
题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...
- 【CodeForces 997C】Sky Full of Stars(组合计数)
题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...
- 【codeforces 812C】Sagheer and Nubian Market
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...
- 【codeforces 508B】Anton and currency you all know
[题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...
- 【codeforces 711B】Chris and Magic Square
[题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...
- 【codeforces 807C】Success Rate
[题目链接]:http://codeforces.com/contest/807/problem/C [题意] 给你4个数字 x y p q 要求让你求最小的非负整数b; 使得 (x+a)/(y+b) ...
最新文章
- 【资源分享】639页《深度学习:Deep Learning》硬核课程PPT
- android 读取sd卡中的图片
- oracle统计事务,统计Oracle 查询事务数的方法
- Confluence 6 中样式化字体
- 《Android传感器开发与智能设备案例实战》——第2章,第2.4节安装ADT
- git学习创建项目仓库
- collection配置说明
- 洛谷 P1019 单词接龙
- idea 查看jsp是否被引用_IntelliJ IDEA解析JSP中的Web路径
- Jquery一些常见性能的问题
- 白板机器学习笔记 P39-P45 指数族分布
- 不会真有人觉得聊天机器人难吧——微调BERT模型得到句子间的相似度
- ubuntu20.04下开发海康威视网络摄像头sdk(一)运行示例程序
- 关键词: iostream 和 iostream.h
- 服务器自动几点重启php,windows下apache及mysql定时自动重启服务器定时自动重启...
- 源码分享—《Java多线程编程核心技术》源码,Java多线程编程核心技术源码 略微有改动。
- OpenKG开源系列|开源知识图谱融合工具OpenEA (南京大学)
- android设置左右声道音量,android控制左右声道实例
- antd 阿里图标库扩展a-icon 图标
- Oralce细粒度审计