【Codeforces 986B】Petr and Permutations
生活随笔
收集整理的這篇文章主要介紹了
【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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 题解 【USACO 4.2.1】草地排
- 下一篇: wamp解决ajax跨域问题