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. Asp.net 插入或更改查询字符串

    string InsertOrUpdateQueryStringItem(string key, string value) { if (Request.QueryString.HasKeys()) ...

  2. ${pageContext.request.contextPath}的作用

    刚开始不知道是怎么回事,在网上也查找了一些资料,看了还是晕. 看了另一个大侠的,终于有了点眉目. 那位大侠在博客中这样写道“然后在网上找,更让我郁闷的事,TMD!网上“抄袭”的真多啊!而且扯了一大堆! ...

  3. Morn简介及使用教程

    [Morn UI系列教程]Morn简介及使用教程 网页游戏开发的一大部分工作是在和UI制作上,一个好的工具及框架能使开发事半功倍,Adobe自带flash IDE和Flex各有不足. Morn UI学 ...

  4. 分享Mvc3+NInject+EF+LigerUI权限系统Demo

    前段时间时不时看到有园友的分享权限系统,于是本人突发奇想,也想写一个玩玩,就利用晚上时间,陆陆续续花了一周多样子,写了如今这个权限系统,这个权限系统具有 组织结构.用户.角色.菜单,组织结构下挂用户, ...

  5. Socket的粘包处理

    Socket的粘包处理 当socket接收到数据后,会根据buffer的大小一点一点的接收数据,比如: 对方发来了1M的数据量过来,但是,本地的buffer只有1024字节,那就代表socket需要重 ...

  6. elasticsearch data importing

    ElasticSearch stores each piece of data in a document. That's what I need. Using the bulk API. Trans ...

  7. Arduino 各种模块篇 震动模块 vibrator

    vibrator is a good thing. it has multi-funtionality . :) Now the  vibrator we choose is the one whic ...

  8. Linux:备份

    一.每日备份数据 该脚本backupday.sh用来每日备份你需要备份的文件或目录 使用办法 1)打开脚本修改要备份的目录或文件和备份到的目录(如从A备份到B) 2)修改后运行脚本 需要备份数据时,直 ...

  9. 使用JDK中的安全包对数据进行加解密

    本文以使用DES对称加密算法为例使用jdk对数据进行加密解密. 首先需要了解Provider类,它是jdk引入的密码服务提供者概念,实现了Java安全性的一部分或者全部.Provider 可能实现的服 ...

  10. Unity在安卓的一些路径

    APK安装之后找不到路径 公司的测试机(安卓)基本都是不带SD卡的. APK在安卓手机上安装之后,使用手机助手类的软件打开文件管理,打开 内置SDK卡/Android/data/ 在这个目录下却发现 ...