题意: 给出一个长度为n的序列,求出是谁操作的(原序列为从小到大的序列),Peter的操作次数为3n,Alex的操作次数为7n+1 解析: 我们来看这个序列中的逆序对,逆序对的个数为偶数则操作次数为偶数,逆序对的个数为奇数,则操作次数为奇数 然后树状数组求逆序对即可 #include <bits/stdc++.h> #define mem(a, b) memset(a, b, sizeof(a)) using namespace std; , INF = 0x7fffffff; int c[m…
题意:初始有一个序列[1,2,...N],一次操作可以将任意两个位置的值互换,Petr做3*n次操作:Alxe做7*n+1次操作.给出最后生成的新序列,问是由谁操作得到的. 分析:一个序列的状态可以归为:由原序列操作奇数次得到(简称奇序列):和操作偶数次(偶序列)得到.显然奇序列中,逆序对的个数为奇数:偶序列中,逆序对的个数为偶.当n为奇数时,3*n为奇,7*n+1为偶:n为偶数时正好相反. 用树状数组或归并排序求逆序对即可. #include<iostream> #include<st…
题目传送门 Petr and Permutations 格式难调,题面就不放了. 分析: 胡乱分析+猜测SP性质一波.然后被学长告知:“1~n的排列交换次数与逆序对的奇偶性相同.”然后就愉快地A了. 因为$3n$和$7n+1$的奇偶性是一定不同的,那么就求逆序对的奇偶性然后判断即可.(太久没打逆序对了,都不会打了..一开始还打错了..) Code: //It is made by HolseLee on 26th July 2018 //CF986B #include<bits/stdc++.h…
题目连接: Petr and Permutations 题意:给出一个1到n的序列,Petr打乱了3n次,Um_nik打乱了7n+1次,现在给出被打乱后的序列,求是谁打乱的. 题解:因为给出了一个3*n和一个7*n+1,发现这两个当一个为奇数另一个一定为偶数,所以可以联想和奇偶性质有关.但是这里面要算最短几步能把当前的序列变成1-n.这里我算错~~顺便学了一下如何将置换序列复原. #include<bits/stdc++.h> using namespace std; typedef pair…
A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; ][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }}; ; + + + + 1e9…
B. Anton and Lines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/B Description The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforc…
题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r,的k的个数.求 i, j (1 ≤ i < j ≤ n) ,f(1, i, ai) > f(j, n, aj).,有多少对满足条件的i.j. 分类:逆序数.线段树.离散化, 分析:这是一道不错的数据结构题目,比較灵活. 推一下第一组例子之后发现时让求一个逆序数的题目.可是不是单纯的求逆序数. 第一…
Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/problem/E Description Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to gene…
题目链接:http://codeforces.com/problemset/problem/351/B 题意: 给你一个1到n的排列a[i]. Jeff和Furik轮流操作,Jeff先手. Jeff每次会交换a[i]>a[i+1]的两个数. Furik每次有1/2的概率交换a[i]<a[i+1]的两个数,有1/2的概率交换a[i]>a[i+1]的两个数. 当这个排列变成升序时,游戏停止. 问你操作数的期望. 题解: 假设原序列中有t个逆序对. 那么将这个序列变成升序,就是将这t个逆序对一…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 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)…
传送门:https://codeforces.com/contest/540/problem/E 题意: 有一段无限长的序列,有n次交换,每次将u位置的元素和v位置的元素交换,问n次交换后这个序列的逆序对个数为多少 题解: 因为值域范围为1e9,而n的范围只有1e5,所以我们肯定是不能直接交换的,对n次操作离散化,离散化后的数组最大为2e5,这里需要用到一些离散化的技巧. 将每次交换的u,v两个点放到map里面,键为pos,值为0 然后对于map映射,值就是离散化后的下标 离散化后我们应该做什么…
题目链接:https://codeforces.com/contest/1427/problem/D 题意 给出一个大小为 \(n\) 的排列,每次操作可以将 \(n\) 个数分为 \(1 \sim n\) 个非空连续份,然后将对称的份两两交换,试给出在 \(n\) 次操作内将排列排为升序的操作过程. 题解 找到值相差为 \(1\) 的逆序对:\(i<j\),\(a_i = a_j + 1\) 将已为升序的数视为一个整体,找到 \(t\) 满足 \(i \le t < j\),\(a_t &g…
题目 传送门:QWQ 分析 思维要求比较高. 首先我们要把原图的逆序对q算出来. 这个树状数组或归并排序都ok(树状数组不用离散化好评) 那么翻转$[l,r]$中的数怎么做呢? 暴力过不了,我试过了. 设$ t=r-l+1 $即为区间长度 那么区间数对数量(看好是所有数对,不是逆序对)的数量就是$ k =\frac{n\times(n-1)}{2} $ 方法是我们判断一下数量k的奇偶性,如果是奇数的,那么就把$ q $的奇偶性变一变. 然后判断q的奇偶性输出就行. 为什么这样是对的呢? 首先翻转…
题目链接: D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her…
题目链接: C. Mashmokh and Reverse Operation time limit per test 4 seconds memory limit per test 512 megabytes input standard input output standard output Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university…
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<i…
题目链接 题目大意 给你一个长度为n的字符串,可以交换相邻两个元素,使得这个字符串翻转,求最少多少种次数改变 题目思路 如果要求数组排序所需要的冒泡次数,那其实就是逆序对 这个也差不多,但是如果是相同字符,用的应该是对应的最近的这个字母. 代码 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=2e5+5; int n,cnt[30],ans[maxn],tree[maxn<…
题意:给你一个字符串,每次可以调换现字符串的相邻两个字符,问最少操作多少次使得这个字符串等于其反转过来的字符串. 题解:先考虑字符串中没有相同字符的情况,那么我们每次将目前字符串的最后一个字符一直调换到前面就行,如果出现相同字符的话,先让最靠前的字符调换到对应位置一定是最优的.我们先记录原字符串中每个字符的位置,然后将字符串反转,根据反转后的字符位置弄一个新数组,注意相同字符一定要把小的位置放在前面,然后用树状数组求个逆序对即可. 代码: #define int long long int n;…
Crossings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description Given a permutation P of {0, 1, ..., n − 1}, we define the crossing number of it as follows. Write the sequence 0, 1, 2, . . . , n − 1 from left to ri…
Crossings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent…
http://codeforces.com/problemset/problem/911/D 题意 给你一个长度为N的序列,有M次操作.每次翻转[l,r]的区间,每次操作后询问序列逆序对个数的奇偶性 很显然问题每次操作之后的变化数量只与区间内自身的逆序数对有关,比较麻烦的操作是翻转的操作. 但是本题的问题是逆序数对的奇偶性,事实上经过仔细的比较发现,整个序列翻转后的逆序数对与被翻转的区间内数字无关,只和区间长度有关. 区间(l,r)内所有数字的对数是(r - l + 1) * (r - l) /…
Crossings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description Given a permutation P of {0, 1, ..., n − 1}, we define the crossing number of it as follows. Write the sequence 0, 1, 2, . . . , n − 1 from left to ri…
Petya and Array http://codeforces.com/problemset/problem/1042/D time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya has an array aa consisting of nn integers. He has learned partial sums…
题意翻译 Petr要打乱排列.他首先有一个从 111 到 nnn 的顺序排列,然后进行 3n3n3n 次操作,每次选两个数并交换它们. Alex也要打乱排列.他与Petr唯一的不同是他进行 7n+17n+17n+1 次操作. 给定一个 111 到 nnn 的排列.问是由谁打乱的.如果是Petr,输出"Petr",否则输出"Um_nik"(不是Alex) 感谢@AKEE 提供翻译 题目描述 Petr likes to come up with problems abo…
每次交换:逆序对的数量+1或者-1: 假设最后逆序对数量为 sum; ①x+y=3n; ②x-y=sum; -> 3n+sum为偶数: 所以 n 和 sum 必须奇偶一样: #include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #include<cstring> #include<string> #include<cmath>…
Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a sequence of numbers {a1, a2, ..., an}, in which every number from 1 to n appears exactly once. One day Anton got a new permutation and…
题目:Problem - D - Codeforces 题解 此题是给数组排序的题,操作是选取任意三个数,然后交换他们,确保他们的位置会发生改变. 可以交换无限次,最终可以形成一个不下降序列就输出"YES",否则"NO". 只需要注意以下两点即可解出此题: 1.如果数组中存在两个相同的元素,那么就一定满足题意,输出"YES" (因为这样就可以移动任意第三个数且保证另外两个相同的数位置不变) 2.因为不下降序列的逆序对数量为0,且每次进行交换操作一…
Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依次删除m个元素,你的任务是在每次删除一个元素之前统计整个序列的逆序对数. Input 输入第一行包含两个整数n和m,即初始元素的个数和删除的元素个数.以下n行每行包含一个1到n之间的正整数,即初始排列.以下m行每行一个正整数,依次为每次删除的元素.   Output   输出包含m行,依次为删除每个元素之前,逆序对的个数. Sample Input 5 4 1…
描述 你一定玩过八数码游戏,它实际上是在一个3*3的网格中进行的,1个空格和1~8这8个数字恰好不重不漏地分布在这3*3的网格中. 例如:5 2 81 3 _4 6 7 在游戏过程中,可以把空格与其上.下.左.右四个方向之一的数字交换(如果存在).例如在上例中,空格可与左.上.下面的数字交换,分别变成:5 2 8       5 2 _      5 2 81 _ 3       1 3 8      1 3 74 6 7       4 6 7      4 6 _ 奇数码游戏是它的一个扩展,…
Ping pong Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3109   Accepted: 1148 Description N(3<=N<=20000) ping pong players live along a west-east street(consider the street as a line segment). Each player has a unique skill rank. To i…