URAL 1100. Final Standings (排序)

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 are too many teams and that software works too slow. You are asked to write a program, which generates exactly the
same final standings as old software, but fast.

Input

The first line of input contains only integer 1 < N ≤ 150000 — number of teams. Each of the next Nlines contains two integers 1 ≤ ID ≤ 107 and
0 ≤ M ≤ 100. ID — unique number of team, M — number of solved problems.

Output

Output should contain N lines with two integers ID and M on each. Lines should be sorted by M in descending order as produced by bubble sort (see below).

Sample

input output
8
1 2
16 3
11 2
20 3
3 5
26 4
7 1
22 4
3 5
26 4
22 4
16 3
20 3
1 2
11 2
7 1

Notes

Bubble sort works following way:

while (exists A[i] and A[i+1] such as A[i] < A[i+1]) do

   Swap(A[i], A[i+1]);

题意:按第二元素排序,若两者相同,不改变两者原来的相对前后关系。

解析:sort + 记录一下初始位置即可。

AC代码:

#include <cstdio>
#include <algorithm>
using namespace std;

struct node{
    int x, y, id;             //id记录初始位置
}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;
}
时间: 2024-08-26 20:34:51

URAL 1100. Final Standings (排序)的相关文章

1100 final standings

http://acm.timus.ru/problem.aspx?space=1&num=1100 link to the problem make a fast stable sorting algorithm. what is sort in c, quick sort. what is a stable sort? a sorting algorithm is said to be stable if two objects with equal keys appear in the sa

zoj1444 Final Standings解题报告

题目大意:本题是模拟ACM比赛中的排名规则,根据所给的信息来输出一个Final Standings(最后的榜单)!! 规则如下: 1,排名按照AC的题数降序排列: 2,AC了同样的题数,那么就按照解题的Total penalty time升序排列(花的时间少肯定排前) 3,如果排名一样(意思是AC题数和总时间都一样),就按照队名的字典序升序排列,但是注意which should be case-insensitive    (不分大小写) 另外: 1,一个题目被solved  仅当获得AC 2,

6.你以为你真的了解final吗?

1. final的简介 final可以修饰变量,方法和类,用于表示所修饰的内容一旦赋值之后就不会再被改变,比如String类就是一个final类型的类.即使能够知道final具体的使用方法,我想对final在多线程中存在的重排序问题也很容易忽略,希望能够一起做下探讨. 2. final的具体使用场景 final能够修饰变量,方法和类,也就是final使用范围基本涵盖了java每个地方,下面就分别以锁修饰的位置:变量,方法和类分别来说一说. 2.1 变量 在java中变量,可以分为成员变量以及方法

完全弄懂后缀数组

什么叫后缀数组  首先要知道什么叫后缀 比如 字符串 abcdef  那么 abcdef bcdef cdef def ef f 就叫做后缀  也就是从最后一个字母之前的一个字母开始一直到最后一个字母  所构成的字符串就叫做后缀 至于后缀数组能干什么?我在这就不介绍了  我想你既然知道后缀数组就一定知道他的用处 但是自己之前读过很多后缀数组的文章  短短二三十代码  却没有找到一篇博客从头到尾讲解的 自己断断续续一个月终于算是对倍增算法(就是一个名字  不必纠结什么叫倍增算法)的有个比较深入理解

用c#开发微信 (17) 微活动 3 投票活动 (文本投票)

前面介绍了微活动<大转盘> 和 <刮刮卡>,这次介绍下微投票,微投票分二种,一种是文本投票, 一种是图片投票.   下面介绍文本投票的详细步骤: 1. 新建文本投票活动     代码实现: <div class="tab-content" > <dl> <dt>投票标题:</dt> <dd> <asp:TextBox runat="server" ID="title&

并发编程-锁相关的内存语义

锁的内存语义本质上可以说是对共享变量的更新,能及时让其他线程观察到:并且通过内存屏障,组织编译器或处理器指令重排序,导致多线程下不一致的现象. 1. volatile内存语义 见上一篇文章. 2. 锁的内存语义 (1)锁的释放和获取的内存语义 当线程释放锁时,JMM会将本地内存中的共享变量同步到主内存中: 当线程获取锁时,JMM会将该线程对应的本地内存置为无效,从而使得被监视器保护的临界区代码必须从主内存中读取共享变量. (2)锁内存语义的实现 ReentrantLock的实现依赖于Abstra

Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved pi problems. Since

1.22训练赛 --ac2

Final standings Solved: 2 out of 7 ac:A题水题  b题思维题 b题: B. Diagonal Walking v.2 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mikhail walks on a Cartesian plane. He starts at the point (0,0

Problem: The World Final II(NEUOJ1175)排序+动态规划

The World Final is coming! Next week our seniors, Brother Head, Little Bin and God Tan will fight for the glory of NEU. The rule of the world final is as follow: 1. if two teams have the different solved problems, then the one who have more solved pr