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. Javascript_Dom编程 阅读笔记(1)

    寻找html页面中的节点 所有文档节点getElementsByTagName("*"); document.getElementsByTagName("*") ...

  2. iOS核心应用对象

    IOS应用之设计模式:模型-视图-控制器 iOS应用与其它应用的区别就在于它所管理的数据(和相应的业务逻辑)以及将数据展现给用户的方式.大多数UIKit对象并不定义应用而是帮助完善其行为.例如,你的应 ...

  3. android引导页的实现 及跳转到主页面

    第一个activity package com.qualitypicture.activity; import java.util.ArrayList; import java.util.List; ...

  4. windows窗体继承问题

    窗体继承什么时候用的到呢?当我们使用三层架构来编写我们的cs程序时,我们的U层大部分是windows窗体.这个时候如果我们有一些公共变量,或者是一个窗体需要使用另一个窗体的数据.或者是有一些用于判断的 ...

  5. mysql提示Column count doesn't match value count at row 1错误

    mysql提示Column count doesn't match value count at row 1错误,后来发现是由于写的SQL语句里列的数目和后面的值的数目不一致, 比如insert in ...

  6. Java实践 — SSH远程执行Shell脚本(转)

    原文地址:http://www.open-open.com/lib/view/open1384351384024.html 1. SSH简介         SSH是Secure Shell的缩写,一 ...

  7. linux上安装Jmeter

    一.首先,你的linux上要有jdk,没有的话请参考上一篇 http://www.cnblogs.com/bigshan-1/p/6242991.html 二.延续上篇的linux用户xiaoming ...

  8. [coding horror] 1 - sum 2

    sum 2 描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 对应每个测试案例,输出两个数,小的先输出. codi ...

  9. nio简介

    上一篇  Java I/O演进与Linux网络I/O模型 一.传统BIO java传统bio编程概念: http://www.cnblogs.com/carl10086/p/6034563.html# ...

  10. 分享基于.NET MVC+EF CodeFirst+IOC+EasyUI的框架设计

    **注:要做工,没什么时间,等有空时会上传到GIT,项目结构如上,简单的说一下: **支持IOC及多数据库等,各项目由MVC区域隔离: 主要使用基于接口与抽象类进行高度的抽象与接口隔离,与其它框架比较 ...