H-frosh Week
crawling in process ... crawling failed time limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64u
Description
During Frosh Week, students play various fun games to get to know each other and compete against other teams. In one such-game, all the Frosh-a team stand in a line, and is then asked to arrange themselves according to some crit Erion, such as their height, their birth date, or their student number. This rearrangement of the line must is accomplished only by successively swapping pairs of consecutive students. The team that finishes fastest wins. Thus, in order to win, you would like to minimize the number of swaps required.
Input
The first line of input contains one positive an integer n, the number of students on the team, which'll be is no more than on E million. The following n lines each contain one integer and the student number of each student on the team. No student number would appear more than once.
Output
Output a line containing the minimum number of swaps required to arrange the students in increasing order by student Numbe R.
Sample Input
3 3 1 2
Sample Output
2 Problem Analysis: Obviously this is a question of reverse order number, can be solved by merging sort.
1#include"Cstdio"2 3 intnum[1000005];4 intt[1000005];5 __int64 sum;6 voidMsetintN)7 {8 for(intI=1; i<=n;i++)9scanf ("%d",&num[i]);Ten } One voidpxintXinty) A { - if(Y-x >1) - { the intm = x + (y-x)/2; - intp = x,q = M,i =x; - px (x,m); - px (m,y); + while(P < m | | Q <y) - { + if(q >= y | | (P < m && Num[p] <=Num[q])) At[i++] = num[p++]; at Else - { -t[i++] = num[q++]; -Sum + = mp; - } - } in for(i=x;i<y;i++) -Num[i] =T[i]; to } + } - intMain () the { * intN; $ while(~SCANF ("%d",&N))Panax Notoginseng { -sum=0; the Mset (n); +px1, n+1); A for(intI=1; i<=n;i++) theprintf ("%d", Num[i]); +printf ("%i64d\n", sum); - } $ $ return 0; -}
View Code
Summer Camp (2)-----frosh Week (UVA11858)