URAL 1100. Final Standings (sort)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.