【CUGBACM15级BC第32场 A】hdu 5182 PM2.5
来源:互联网 发布:mysql编程题及答案 编辑:程序博客网 时间:2024/06/07 00:49
PM2.5
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1528 Accepted Submission(s): 748
Total Submission(s): 1528 Accepted Submission(s): 748
Problem Description
Nowadays we use content of PM2.5 to discribe the quality of air. The lower content of PM2.5 one city have, the better quality of air it have. So we sort the cities according to the content of PM2.5 in asending order.
Sometimes one city’s rank may raise, however the content of PM2.5 of this city may raise too. It means that the quality of this city is not promoted. So this way of sort is not rational. In order to make it reasonable, we come up with a new way to sort the cityes. We order this cities through the diffrence between twice measurement of content of PM2.5 (first measurement – second measurement) in descending order, if there are ties, order them by the second measurement in asending order , if also tie, order them according to the input order.
Sometimes one city’s rank may raise, however the content of PM2.5 of this city may raise too. It means that the quality of this city is not promoted. So this way of sort is not rational. In order to make it reasonable, we come up with a new way to sort the cityes. We order this cities through the diffrence between twice measurement of content of PM2.5 (first measurement – second measurement) in descending order, if there are ties, order them by the second measurement in asending order , if also tie, order them according to the input order.
Input
Multi test cases (about 100 ), every case contains an integer n which represents there are n cities to be sorted in the first line.
Cities are numbered through 0 ton−1 .
In the nextn lines each line contains two integers which represent the first and second measurement of content of PM2.5
The ith line describes the information of cityi−1
Please process to the end of file.
[Technical Specification]
all integers are in the range[1,100]
Cities are numbered through 0 to
In the next
The ith line describes the information of city
Please process to the end of file.
[Technical Specification]
all integers are in the range
Output
For each case, output the cities’ id in one line according to their order.
Sample Input
2100 11 23100 503 41 2
Sample Output
0 10 2 1
题意:每一个城市有两个权值,先按照第一权值-第二权值降序排序,如果第一权值-第二权值相等,再按照第二权值排序,否则按照输入的顺序排序
思路:直接sort即可,三级排序#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;struct Node{ int v, w; int id;} a[10000];bool cmp(Node a, Node b){ if (a.v == b.v && a.w == b.w) { return a.id < b.id; } if (a.v == b.v) { return a.w < b.w; } return a.v > b.v;}int main(){ int n; while (~scanf("%d", &n)) { for (int i = 0; i < n; i++) { scanf("%d %d", &a[i].v, &a[i].w); a[i].v -= a[i].w; a[i].id = i; } sort(a, a + n, cmp); for (int i = 0; i < n - 1; i++) { printf("%d ", a[i].id); } printf("%d\n", a[n - 1].id); } return 0;}
阅读全文
0 0
- 【CUGBACM15级BC第32场 A】hdu 5182 PM2.5
- 【CUGBACM15级BC第15场 A】hdu 5083 Love
- 【CUGBACM15级BC第17场 A】hdu 5100 Chessboard
- 【CUGBACM15级BC第23场 A】hdu 5146 Sequence
- 【CUGBACM15级BC第8场 A】hdu 4989 Summary
- 【CUGBACM15级BC第31场 A】hdu 5178 pairs
- 【CUGBACM15级BC第1场 A】hdu 4857 逃生
- 【CUGBACM15级BC第12场 A】【STL】hdu 5058 So easy
- 【CUGBACM15级BC第11场 A】hdu 5054 Alice and Bob
- 【CUGBACM15级BC第13场 A】hdu 5062 Beautiful Palindrome Number
- 【CUGBACM15级BC第18场 A】hdu 5104 Primes Problem
- 【CUGBACM15级BC第20场 A】hdu 5123 who is the best?
- 【CUGBACM15级BC第19场 A】hdu 5108 Alexandra and Prime Numbers
- 【CUGBACM15级BC第21场 A】hdu 5138 CET-6 test
- 【CUGBACM15级BC第22场 A】hdu 5142 NPY and FFT
- 【CUGBACM15级BC第24场 A】hdu 5150 Sum Sum Sum
- 【CUGBACM15级BC第24场 C】hdu 5152 A Strange Problem
- 【CUGBACM15级BC第25场 A】hdu 5154 Harry and Magical Computer
- 关于从客户端中检测到有潜在危险的 Request.Form 值
- linux下 如何切换到root用户
- Android 5.1 Material Design 中Color 设置
- CF854C planning 贪心题,维护堆; 送棵线段树
- CSS(5)
- 【CUGBACM15级BC第32场 A】hdu 5182 PM2.5
- 1094:多输入输出练习2
- Linux 技巧:让进程在后台可靠运行的几种方法
- 深度卷积网络CNN与图像语义分割
- DrawerLayout 侧滑
- 51Nod- 1006 最长公共子序列Lcs(动态规划)
- 关于ffmpeg的一个bug长期求解答
- Elasticsearch&logstash&filebeat&kibana&x-pack搭建
- 深入理解HashSet