ural 1100. Final Standings -排序
来源:互联网 发布:查看linux oracle监听 编辑:程序博客网 时间:2024/06/17 02:41
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 nextN lines 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 integersID andM 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]);
题意
根据m将n个数按冒泡排序法则排序 输出结果
解题思路
冒泡排序 TLE 了,sort 是不稳定的排序。
stable_sort的用法与sort一致,区别是stable_sort函数遇到两个数相等时,不对其交换顺序
当函数参数传入的是结构体时,会发现两者之间的明显区别;
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <functional>#include <algorithm>#include <bits/stdc++.h>using namespace std;const int INF = 0x3f3f3f3f;struct Node{ int id,m;}node[150010];bool cmp(const Node &a,const Node &b){ return a.m>b.m;}int main(){ int n; scanf("%d",&n); for(int i=0;i<n;++i){ scanf("%d%d",&node[i].id,&node[i].m); } stable_sort(node,node+n,cmp); for(int i = 0;i<n;++i){ printf("%d %d\n",node[i].id,node[i].m); } return 0;}
1 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 拓扑排序
- Ural 1022 拓扑排序
- URAL 1522 Factory 特殊排序
- TOJ 2881.Biased Standings
- tree standings 树 && dp
- 【基础拓扑排序】poj 2376/ural 1022
- Ubuntu14.04 修改MAC地址-永久(临时)修改 Linux
- ORA-00845: MEMORY_TARGET not supported on this system
- NYOJ456 邮票分你一半(转化为01背包)
- 4412 android系统去掉和添加apk
- 使用 HttpUtil 调用 接口
- ural 1100. Final Standings -排序
- DWZ 学习
- node.js Buffer对象(模块详解)
- 【Codeforces 729 C Road to Cinema】 + 二分
- PLSQL Developer中文显示乱码
- Postman工具——请求与响应
- 解决MAC上使用Jenkins各种命令找不到的问题
- 干掉360的方法-Windows7
- 【c++】调试技巧之调用堆栈 - Call stack