【Codeforces 986B】Petr and Permutations
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
n为奇数时3*n和7*n+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 here
new 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());
}
}
}
【Codeforces 986B】Petr and Permutations的更多相关文章
- 【codeforces 760A】Petr and a calendar
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 501D】Misha and Permutations Summation
[题目链接]:http://codeforces.com/problemset/problem/501/D [题意] 给你两个排列; 求出它们的字典序num1和num2; 然后让你求出第(num1+n ...
- 【Codeforces 113B】Petr#
Codeforces 113 B 题意:有一个母串\(S\)以及两个串\(S_{begin}\)和\(S_{end}\),问\(S\)中以\(S_{begin}\)为开头并且以\(S_{end}\)为 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 602E】Kleofáš and the n-thlon
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【25.00%】【codeforces 584E】Anton and Ira
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
随机推荐
- VS2015 framework4.5代码提示英文切换为中文
输入下面的地址,复制里面所有的文件 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 ...
- bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐【dfs】
从每个奶牛所在草场dfs,把沿途dfs到的草场的con都+1,最后符合条件的草场就是con==k的,扫一遍统计一下即可 #include<iostream> #include<cst ...
- golang——随机数(math/rand包与crypto/rand包)
1.math/rand 包 1.1.math/rand 包实现了伪随机数生成器 1.2.主要方法 (1)func Seed(seed int64) 设置随机种子,不设置则默认Seed(1) (2)fu ...
- $割点割顶tarjan$
原题 #include <bits/stdc++.h> using namespace std; typedef long long LL; inline LL read () { LL ...
- Android 性能优化(1)性能工具之「 lint 」 :Improving Your Code with lint:优化代码
Improving Your Code with lint 1.See Also lint (reference) Using Android Annotations In addition to t ...
- cocos creator 场景如何透明,多个canvas层级显示
转载地址:https://forum.cocos.com/t/creator-canvas/55373/14 Creator 版本:1.7 目标平台:WEB MOBILE 项目需要,页面做了多个Can ...
- TFS修改了工作区
计算机修改名字后,更换了TFS工作区,但原工作区的有些文件忘记签入: 解决方案: 删除原工作区即可,实现:到TFS工作区 - “管理工作区”,选中“显示远程工作区”,找到原工作区,删除即可.
- C#,VB.NET将PPT文档转换为HTML
PPT文档主要用于展示,有时候我们需要将PPT文档转换为HTML格式方便查看.本文将介绍如何使用C#和VB.NET将PPT文档转换为HTML格式.该方案使用了.NET PowerPoint 组件Spi ...
- 动态调用链接库(dll) 续
20141118 最近一周做了一个关于仓库管理,拣货任务分配的模块,其中涉及到刷卡自动打印领取任务的功能点. 技术点: C#调用C++.delphi的动态链接库.动态链接库的调用方法不同.效果也不相同 ...
- 02使用常规步骤编译NanoPiM1Plus的Android4.4.2
02使用常规步骤编译NanoPiM1Plus的Android4.4.2 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2017/12/5 17:51 版本 ...