【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

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的更多相关文章

  1. 【codeforces 760A】Petr and a calendar

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【codeforces 501D】Misha and Permutations Summation

    [题目链接]:http://codeforces.com/problemset/problem/501/D [题意] 给你两个排列; 求出它们的字典序num1和num2; 然后让你求出第(num1+n ...

  3. 【Codeforces 113B】Petr#

    Codeforces 113 B 题意:有一个母串\(S\)以及两个串\(S_{begin}\)和\(S_{end}\),问\(S\)中以\(S_{begin}\)为开头并且以\(S_{end}\)为 ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 【codeforces 602E】Kleofáš and the n-thlon

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【25.00%】【codeforces 584E】Anton and Ira

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  8. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. 关于mfc添加热键

    对于mfc的添加热键的文章已经有很多了,我这里就简单的说一下并且说一些可能出的错误 首先在资源文件中添加ACCELERATOR然后在资源文件下的RC中找到ACCELERATOR的节点,打开后可以发现一 ...

  2. JS 实现PDF文件打印

    function PdfPrint() {        bdhtml = window.document.body.innerHTML;        sprnstr = "<!-- ...

  3. 清理TIME_WAIT

    cat >> /etc/sysctl.conf << EOFnet.ipv4.tcp_tw_reuse=1net.ipv4.tcp_tw_recycle=1net.ipv4.t ...

  4. hdu2033

    http://acm.hdu.edu.cn/showproblem.php?pid=2033 1 #include<stdio.h> #include<string.h> #i ...

  5. HTML DOM getElementById() 方法

    定义和用法 getElementById() 方法可返回对拥有指定 ID 的第一个对象的引用. 语法 document.getElementById(id) 说明 HTML DOM 定义了多种查找元素 ...

  6. java 选择排序与冒泡排序

    选择排序与冒泡排序的特点与区别 ++++++++++++++++++++++++++++++++++++++++++++++ 选择排序 这一种简单的排序方法,它的基本思想是:R[n]第一次从R[0]~ ...

  7. MacOS 下安装 MySQL8.0 登陆 MySQL

    按照 官方教程 ,下载安装包,点击安装后,如需在命令行启动,还需设置命令路径: 在命令行中,打开配置文件 .bash_profile: vim ~/.bash_profile 在最后一行加上: PAT ...

  8. 观察者模式(observer)c++实现

    1意图 定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. 2别名 依赖(Dependents), 发布-订阅(Publish-Subscribe ...

  9. [ Nowcoder Contest 167 #C ] 部分和

    \(\\\) \(Description\) 给出一个长度为\(N\)的数组\(A[i]\),保证\(N\)为 \(2\) 的整次幂. 对于每个 \(i\ (i\in [0,N))\)求所有满足\(( ...

  10. C++(Typedef声明)

    typedef 声明: 使用 typedef 为一个已有的类型取一个新的名字.下面是使用 typedef 定义一个新类型的语法: typedef type newname; 例如,下面的语句会告诉编译 ...