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
题意很简单。。。。
 
原以为用sort排个序即可。。。
 
wrong了后才发现,在value相等的情况下,不能对元素进行交换。。而sort(用的是快排,是不稳定的排序方式,因而会打乱顺序)
 
那要怎么办呢?
 
问了学长才知道有个叫做stable_value的东西~~
 

所谓stable_sort,是指对一个序列进行排序之后,如果两个元素的值相等,则原来乱序时在前面的元素现在(排好序之后)仍然排在前面。STL中提供stable_sort()函数来让我们进行稳定排序。为了更好的说明稳定排序的效果,我们定义了一个结构体元素,一个value成员和一个index成员,前者表示元素的值,后者表示乱序时的索引。

AC代码:

 #include<cstdio>
#include<iostream>
#include<algorithm> using namespace std;
struct node
{
long id;
int m;
bool operator<(const node&temp) const
{
return m>temp.m;
}
}kiss[+]; int main()
{
// freopen("input.txt","r",stdin);
int n;
while(cin>>n){
for(int i=;i<n;i++){
scanf("%ld%d",&kiss[i].id,&kiss[i].m);
}
stable_sort(kiss,kiss+n);
for(int i=;i<n;i++){
printf("%ld %d\n",kiss[i].id,kiss[i].m);
}
}
return ;
}

ural 1100. Final Standings(数据结构)的更多相关文章

  1. 1100 final standings

    http://acm.timus.ru/problem.aspx?space=1&num=1100 link to the problem make a fast stable sorting ...

  2. 1.13抽象类及接口(附简述final关键字)

    一.final final的中文意思就是不可更改的,最终的. 1.final修饰变量,那么该变量无法更改.一旦该变量赋了初值,就不能重新赋值. final MAX = 1100; //final修饰后 ...

  3. pachi 学习

    修改 Makefile DCNN=1 -> DCNN=0 // 禁用DCNN #BOARD_SIZE=19 -> BOARD_SIZE=19 // 棋盘大小19x19 OPT ?= -O3 ...

  4. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem C. Contest 水题

    Problem C. Contest 题目连接: http://codeforces.com/gym/100714 Description The second round of the annual ...

  5. PTA 1139 1138 1137 1136

    PAT 1139 1138 1137 1136 一个月不写题,有点生疏..脑子跟不上手速,还可以啦,反正今天很开心. PAT 1139 First Contact 18/30 找个时间再修bug 23 ...

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

    链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...

  7. [C++]Yellow Cards - GYM - 102348A(Practice *) - CodeForces

    1 Problem Description Problem The final match of the Berland Football Cup has been held recently. Th ...

  8. [JZOJ6089]【CodeChef 2014 April Challenge】Final Battle of Chef【数据结构】【整体二分】

    Description \(n,q,V\leq 100000,w_i\leq 10^9\) Solution 又是一道大数据结构 由于有一个下取整,这就导致了不同时间的修改值是不能简单的直接加在一起的 ...

  9. Java数据结构: java.util.BitSet源码学习

    接着上一篇Blog:一道面试题与Java位操作 和 BitSet 库的使用,分析下Java源码中BitSet类的源码. 位图(Bitmap),即位(Bit)的集合,是一种常用的数据结构,可用于记录大量 ...

随机推荐

  1. Android开发效率的小技巧

    提高eclipse使用效率(二) 提高Android开发效率的小技巧   XML文件的代码提示 adt中也有xml文件的代码提示,为了让提示来的更加猛烈,我们还要设置一下 打开eclipse - Wi ...

  2. WINDOWS下安装PHP7出现PHP-CGI无法启动

    事情经过:下载PHP 7.0 然后运行,发现php-cgi一直挂掉.启动不起来.我直接到文件夹下启动PHP-CGI 启动, 失败,报错提示:缺失vcruntime140.dll.当时心中暗暗一笑,当年 ...

  3. 进程间通讯之mmap文件共享

    进程间通讯之mmap文件共享 引文: 个人名言:“同一条河里淹死两次的人,是傻子,淹死三次及三次以上的人是超人”.经历过上次悲催的面试,决定沉下心来,好好的补充一下基础知识点.本文是这一系列第一篇:进 ...

  4. jquery简单封装

    对Raphael画图标的一个jquery简单封装 公司要做一个项目的demo,要求地图上可以插红旗,所以就用到了Raphael. 因为是个demo,所以地图就用了一张图片,效果如下: 所以为了更好的封 ...

  5. Ping其他电脑ping不通的解决方法

    要想Ping通其他电脑,首先要看被PING的电脑,是否允许PING. 一.在被PING电脑操作系统为XP下分为:1.被PING 电脑关闭了防火墙,就完全可以PING通:2.被PING 电脑开了防火墙, ...

  6. Mathematics for Computer Graphics

    Mathematics for Computer Graphics 最近严重感觉到数学知识的不足! http://bbs.gameres.com/showthread.asp?threadid=105 ...

  7. opengl离屏渲染(不需要和窗口绑定,仅当作一个可以渲染一张图片的API使用)+ opencv显示

    具体过程参考的是这篇BLOG: http://wiki.woodpecker.org.cn/moin/lilin/swig-glBmpContext 这一片BLOG的代码有个 BOOL SaveBmp ...

  8. 对比AutoResetEvent和ManualResetEvent

    ManualResetEvent和AutoResetEvent 比较 ManualResetEvent和AutoResetEvent都继承自EventWaitHandler,它们的唯一区别就在于父类 ...

  9. Android_NDK问题:APP_BUILD_SCRIPT points to an unknown file: <project_path>/jni/Android.mk

    问题详情: Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: <path>/jni/Android.mk ...: ...

  10. 深入浅出Mybatis-sql自动生成

    本文提供了一种自动生成sql语句的方法,它针对的对象是有主键或唯一索引的单表,提供的操作有增.删.改.查4种.理解本文和本文的提供的代码需要有java注解的知识,因为本文是基于注解生成sql的.本文适 ...