题目链接: Inversion Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1087    Accepted Submission(s): 323 Problem Description You have a sequence {a1,a2,...,an} and you can delete a contiguous subsequ…
题目 题意:  给你一串数字,然后给你最多进行k次交换(只能交换相邻的)问交换后的最小逆序对个数是多少. 给你一个序列,每次只能交换相邻的位置,把他交换成一个递增序列所需要的最少步数 等于 整个序列的逆序对数. 对于这个题目,我们只要求出个逆序对个数,然后输出逆序数 - k就行了,如果是负数输出0. 之前做的这道题也是和逆序对有关,但是通过这道的代码改编一下,总是Runtime Error (ACCESS_VIOLATION),原因在于这里 The first line contains 2 i…
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarant…
Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 388    Accepted Submission(s): 148 Problem Description Given the finite multi-set A of n pairs of integers, an another finite multi-set B …
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意:给你一个0 — n-1的排列,对于这个排列你可以将第一个元素放到最后一个,问你可能得到的最多逆序对的个数 求出原始序列的逆序对的数目,然后进行n-1次将第一个元素放到最后一个的操作,每次操作后可以用O(1)复杂度求得新序列的逆序对数目 此题的关键点在于求出原始序列逆序对的数目,可以使用树状数组, 线段树, 归并等方法. 下面是树状数组的解法 #include <iostream> #i…
题目链接 Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1, a2, ..., an, if we move the first m >= 0 numbers to the e…
The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1, a2, ..., an, if we move the first m >= 0 numbers to the end of the seqence, we wil…
题目链接 题意: 给一个n个数的序列a1, a2, ..., an ,这些数的范围是0-n-1, 可以把前面m个数移动到后面去,形成新序列:a1, a2, ..., an-1, an (where m = 0 - the initial seqence)a2, a3, ..., an, a1 (where m = 1)a3, a4, ..., an, a1, a2 (where m = 2)...an, a1, a2, ..., an-1 (where m = n-1)求这些序列中,逆序数最少的…
题意:有0~n-1这n个数,以一定的排列.这个排列可以循环,就是可以把第一个拿到最后,然后形成新的排列.问这些排列中的逆序对最小值. 思路: 最后的循环,拿走一个之后,新的逆序对数 newsum = oldsum - nowni + ((n-1)-nowni) 其中 ,nowni表示这个数所构成的逆序对数. Nowni = 原数列中此数往后构成的逆对数 + 原数列中此数往前构成的非逆对数. 然后那两个辅助数组,就可以用扫描循环,然后求前面(或后面)比现在这个数大的(或小的)的数有多少.典型的树状…
Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarantee that no two se…