Ultra-QuickSort 题目链接:http://poj.org/problem?id=2299 Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 51641   Accepted: 18948 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequen…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4046 题意:有一个含有n个元素的数列p,每个元素均不同且为1~n中的一个,求出将数列变为循环递增序列至少需要左右相邻的数交换多少次 题目分析:先看简化版的题目:如果只有1 2 3 4 5是符合要求的,那么交换次数根据冒泡排序可得就是逆序数,直接树状数组求逆序数即可. 由于题目要求只要只要是循环递增数列即可,也就是1 2 3 4 5 和 2 3 4 5 1都是符合要求的.那…
Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 46995   Accepted: 17168 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swappin…
题目连接:http://acm.uestc.edu.cn/#/problem/show/931 OJ评判系统有些坑,不支持__int64以及输出的%I64d大家注意.全开long long也会TLE,比较坑.逆序的基础操作题,不错. #include <bits/stdc++.h> #define MAX 100010 using namespace std; ]; struct Node { int x, v; } node[MAX]; bool cmp (Node a, Node b) {…
题目链接 ac代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<bitset> #include<cassert> #include<cctype> #include<cmath> #include<cstdlib> #include<ctime> #include&…
题目链接:http://poj.org/problem?id=2299 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 sequence elements until the sequence is sorted in…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number                        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)                                            Total Submission(s): 10…
树状数组求逆序对   转载http://www.cnblogs.com/shenshuyang/archive/2012/07/14/2591859.html 转载: 树状数组,具体的说是 离散化+树状数组.这也是学习树状数组的第一题. 算法的大体流程就是: 1.先对输入的数组离散化,使得各个元素比较接近,而不是离散的, 2.接着,运用树状数组的标准操作来累计数组的逆序数. 算法详细解释: 1.解释为什么要有离散的这么一个过程? 刚开始以为999.999.999这么一个数字,对于int存储类型来…
链接:https://ac.nowcoder.com/acm/contest/358/D来源:牛客网 出题人的手环 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语言1048576K 64bit IO Format: %lld 题目描述 出题人的妹子送了出题人一个手环,这个手环上有 n 个珠子,每个珠子上有一个数. 有一天,出题人和妹子分手了,想把这个手环从两个珠子间切开,并按顺时针顺序展开成一条链. 可以发现,这条链一共有 n 种可能性.求这 n 种可能性…
链接:http://poj.org/problem?id=2299 题意:给出n个数,求将这n个数从小到大排序,求使用快排的需要交换的次数. 分析:由快排的性质很容易发现,只需要求每个数的逆序数累加起来就行了.逆序数可以用树状数组求. n<500000,0<=a[i]<=999,999,999,很明显数组不可能开这么大,所以需要离散化. 可以用一个结构体 struct node{    int val,pos;}a[N]; pos表示每个数的下标,val表示该数的值 按val从小到大排序…