日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【Codeforces 986B】Petr and Permutations

發布時間:2025/4/16 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。