【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子列的个数; 然后让你输出 ...
随机推荐
- PCB 圆形板切边算法 实现
在工程CAM处理圆形拼板是个头疼的问题,需人工程师自行设计切边 满足可以拼板并且拼板后锣板板边没有内角,不然会影响装配 1.原始单 PCS圆形板 此外形如果不采用邮票孔连接的话,采V-CUT连接须采用 ...
- bzoj 1232: [Usaco2008Nov]安慰奶牛cheer【最小生成树】
有趣 每条边在算答案的时候被算了二倍的边权值加上两个端点的权值,然后睡觉点额外加一次 所以可以用这个权做MST,然后加上点权最小的点 #include<iostream> #include ...
- bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】
二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...
- 公司6:JrVue重用布局
JrVue是我们基于element重新封装的一套组件库; 为了提高开发效率, 方便对代码的统一管理和维护, 我们提供了一些统一的页面布局, 以及项目常用的中小型模块 我在master新拉一个分支J ...
- Linux上安装禅道
linux一键安装包内置了apache, php, mysql这些应用程序,只需要下载解压缩即可运行禅道. 从7.3版本开始,linux一键安装包分为32位和64位两个包,请大家根据操作系统的情况下载 ...
- [算法] 常见排序算法总结(C语言版)
常见排序算法总结 本文对比较常用且比较高效的排序算法进行了总结和解析,并贴出了比较精简的实现代码,包括选择排序.插入排序.归并排序.希尔排序.快速排序等.算法性能比较如下图所示: 1 冒泡排序 基本原 ...
- [Qt Creator 快速入门] 第8章 界面外观
一个完善的应用程序不仅应该有实用的功能,还要有一个漂亮的外观,这样才能使应用程序更加友好,更加吸引用户.作为一个跨平台的UI开发框架,Qt提供了强大而灵活的界面外观设计机制.这一章将学习在Qt中设计应 ...
- 数据返回(数据共享,即从后端返回到前端调用,四种(requesst、ModelAndView、Model、Map))
@Controller @RequestMapping("/view")//请求父路径 public class GoodsController { @RequestMapping ...
- SqlServer知识点-操作xml
一.开发环境 SQL2010 二.开发过程 1.声明一个xml类型变量 DECLARE @xmlInfo XML; SET @xmlInfo = '<CompanyGroup> <C ...
- 【JAVA 学习笔记2】if使用例子
int a =3; if (a%2==0) { System.out.println(a+" 是偶数"); System.out.println(a+" 不是奇数&quo ...