URAL 1100. Final Standings (排序)
来源:互联网 发布:小小dota2数据库 编辑:程序博客网 时间:2024/05/29 15:05
1100. Final Standings
Time limit: 1.0 second
Memory limit: 16 MB
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
81 216 311 220 33 526 47 122 4
3 526 422 416 320 31 211 27 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;}
0 0
- URAL 1100. Final Standings (排序)
- ural 1100. Final Standings -排序
- Ural 1100. Final Standings 桶排序
- Ural 1100. Final Standings
- [URAL 1100]Final Standings(排序技巧)
- Ural 1100 Final Standings
- 1100. Final Standings
- ural1100--Final Standings--数据结构--结构体排序
- Final Standings
- Timus Online Judge:1100. Final Standings
- zoj1444 Final Standings解题报告
- 湖大训练赛第十场 Final Standings
- URAL - 1022 - Genealogical Tree(拓扑排序)
- ural 1306 (heap推排序)
- URAL 1022 拓扑排序
- Ural 1022 拓扑排序
- URAL 1026 - Questions and Answers(计数排序)
- ural 1207. Median on the Plane(极角排序)
- 正则表达式与有穷自动机
- php对文件锁进行加锁、解锁
- 09. 正交概念
- linux 路由表 的一些相关资料
- *LeetCode-Triangle
- URAL 1100. Final Standings (排序)
- 列出所有的配置 Repo 源
- JavaWeb的各种中文乱码终极解决方法
- HDU 1.1.4解题报告
- USACO--1.3Mixing Milk
- 1192 回文字符串
- stl中push_back和浅拷贝和深拷贝的问题
- 做个有计划的人
- 【hibernate框架】缓存机制之一级缓存