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. zookeeper学习(上)

    zookeeper学习(上) 在前面的文章里我多次提到zookeeper对于分布式系统开发的重要性,因此对zookeeper的学习是非常必要的.本篇博文主要是讲解zookeeper的安装和zookee ...

  2. hdu1686

    题目意思:找到上串在下串中有多少个 Problem Description The French author Georges Perec (1936–1982) once wrote a book, ...

  3. Sublime中开发Ruby

    Ruby:Sublime中开发Ruby需要注意的Encoding事项 目录 背景Sublime相关默认的文件存储编码:UTF8默认的输出控制台编码:UTF8修改默认的输出控制台编码Ruby相关默认的代 ...

  4. - 高级篇:二,IL设置静态属性,字段和类型转换

    - 高级篇:二,IL设置静态属性,字段和类型转换 静态属性赋值 先来看 Reflector反射出的IL源码(感谢Moen的提示),这次用 Release模式编译,去掉那些无用的辅助指令 public ...

  5. IL反编译的实用工具

    初识Ildasm.exe——IL反编译的实用工具   Ildasm.exe 概要: 一.前言: 微软的IL反编译实用程序——Ildasm.exe,可以对可执行文件(ex,经典的控制台Hello Wor ...

  6. TOGAF架构内容框架之架构交付物

    TOGAF架构内容框架之架构交付物 3. 架构交付物(Architecture Deliverables) 架构交付物是在整个架构开发方法循环过程中所产生或被使用的契约性且正规化的企业架构内容,因而其 ...

  7. echarts 某省下钻某市地图

    因为最近工作需要,接触到了highcharts 与echarts ,对比了一下,目前公司系统用的是highcharts的图表插件,就不想再去用echarts的图标插件了,奈何highcharts地图对 ...

  8. 内核操作系统Linux内核变迁杂谈——感知市场的力量

    本篇文章个人在青岛游玩的时候突然想到的...今天就有想写几篇关于内核操作系统的博客,所以回家到以后就奋笔疾书的写出来发表了 Jack:什么是操作系统? 我:你买了一台笔记本,然后把整块硬盘彻底格式化, ...

  9. linux环境变量入门

    一.概要 本文用java环境变量配置这个案例来介绍linux下的环境变量是怎样的,并且和windows系统下的环境变量语法进行了相应对比,适合初学者入门.在这之前,我已经将jdk.tomcat和ecl ...

  10. [DL学习笔记]从人工神经网络到卷积神经网络_3_使用tensorflow搭建CNN来分类not_MNIST数据(有一些问题)

    3:用tensorflow搭个神经网络出来 为什么用tensorflow呢,应为谷歌是亲爹啊,虽然有些人说caffe更适合图像啊mxnet效率更高等等,但爸爸就是爸爸,Android都能那么火,一个道 ...