1100. Final Standings
Time limit:1.0 Second
Memory limit:16 MB
Old contest software uses bubble sort for generating final standings. But now, there is too many teams and that software works too slow. You is asked to write a program, which generates exactly the same final standings as old software, but fast. Inputthe first line of input contains only integer 1 <
N≤150000-number of teams. Each of the next
NLines contains, integers 1≤
ID≤107and 0≤
M≤100.
ID-unique Number of Team,
M-number of solved problems. Outputoutput should contain
Nlines with integers
IDand
MOn each. Lines should be sorted by
MIn descending order as produced by bubble sort (see below). Sample
input |
Output |
81 216 311 220 33 526 47 122 4 |
3 526 422 416 320 31 211 27 1 |
Notesbubble Sort Works following:
while (exists A[i] and A[i+1] such as A[i] < A[i+1]) do
Swap(A[i], A[i+1]);
Test instructions: Sort by the second element, if the two are the same, do not change the original relative back and forth relationship.
Parse: Sort + record the initial position.
AC Code:
#include <cstdio> #include <algorithm>using namespace std;struct node{ int x, y, id; ID record initial position}a[150005];int CMP (node AA, node bb) { if (aa.y = = bb.y) return aa.id < bb.id; return aa.y > Bb.y;} int main () { #ifdef sxk freopen ("In.txt", "R", stdin); #endif//sxk int n; while (scanf ("%d", &n) ==1) {for (int i=0; i<n; i++) { scanf ("%d%d", &a[i].x, &a[i].y); A[i].id = i; } Sort (A, a+n, CMP); for (int i=0; i<n; i++) printf ("%d%d\n", a[i].x, A[I].Y); } return 0;}
URAL 1100. Final Standings (sort)