hdoj 5182 PM2.5 排序
PM2.5
Time Limit: 2000/1000
MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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.
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 to n−1.
In the next n 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 city i−1
Please process to the end of file.
[Technical Specification]
all integers are in the range [1,100]
Output
For each case, output the cities’ id in one line according to their order.
Sample Input
2 100 1 1 2 3 100 50 3 4 1 2
Sample Output
0 1 0 2 1
题意
简单来说,每个城市都有两个PM值,排序的时候让你按照两个PM值之差,从大到小排序,然后再按照第二个PM值,从小到大,再按照id从小到大排序
题解
照着题意写cmp,然后调用stl的sort就好~
struct node
{
int x;
int y;
int ss;
int id;
};
bool cmp(node a,node b)
{
if(a.ss==b.ss&&a.y==b.y)
return a.id<b.id;
if(a.ss==b.ss)
return a.y<b.y;
return a.ss>b.ss;
}
node kiss[maxn];
int main()
{
int n;
while(cin>>n)
{
REP(i,n)
{
RD(kiss[i].x);
RD(kiss[i].y);
kiss[i].ss=kiss[i].x-kiss[i].y;
kiss[i].id=i;
}
sort(kiss,kiss+n,cmp);
int flag=1;
REP(i,n)
{
if(flag)
{
cout<<kiss[i].id;
flag=0;
}
else
cout<<" "<<kiss[i].id;
}
cout<<endl;
}
}
hdoj 5182 PM2.5 排序的更多相关文章
- hdu 5182 PM2.5
问题描述 目前,我们用PM2.5的含量来描述空气质量的好坏.一个城市的PM2.5含量越低,它的空气质量就越好.所以我们经常按照PM2.5的含量从小到大对城市排序.一些时候某个城市的排名可能上升,但是他 ...
- HDOJ/HDU 2535 Vote(排序、)
Problem Description 美国大选是按各州的投票结果来确定最终的结果的,如果得到超过一半的州的支持就可以当选,而每个州的投票结果又是由该州选民投票产生的,如果某个州超过一半的选民支持希拉 ...
- HDOJ(HDU) 1862 EXCEL排序(类对象的快排)
Problem Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能. Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<= ...
- hdu 5182 结构体排序
BC # 32 : 打 BC 的时候没看全三个关键字,WA 了五发,花了近一小时,问了一下才发现少看一个条件,于是顺利给跪. 题意:给出若干城市的两次空气质量,首先按空气质量差排序,若相等则按第二次排 ...
- HDOJ 2001 ASCII码排序
#include<set> #include<iostream> using namespace std; int main() { char a, b, c; while ( ...
- 使用page object模式抓取几个主要城市的pm2.5并从小到大排序后写入txt文档
#coding=utf-8from time import sleepimport unittestfrom selenium import webdriverfrom selenium.webdri ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 用python+selenium获取北上广深成五地PM2.5数据信息并按空气质量排序
从http://www.pm25.com/shenzhen.html抓取北京,深圳,上海,广州,成都的pm2.5指数,并按照空气质量从优到差排序,保存在txt文档里 代码如下: #coding=utf ...
- 双拓扑排序 HDOJ 5098 Smart Software Installer
题目传送门 /* 双拓扑排序:抄的,以后来补 详细解释:http://blog.csdn.net/u012774187/article/details/40736995 */ #include < ...
随机推荐
- JavaScript 简单吗
英文:Aurélien Hervé 译文:众成翻译/msmailcode 这里有一些 Javascript初学者应该知道的技巧和陷阱.如果你已经是专家了,顺便温习一下. Javascript也只不过 ...
- MongoDB的安装与使用
MongoDB是一款NoSql数据库.NoSql数据库叫非关系型数据库,NoSql的全名Not only sql.是为了解决高并发.高可用.高可扩展,以及大数据存储等一系列问题而产生的数据库解决方案. ...
- conding.net或github,readme.md添加图片
原因: 将图片放在仓库里面,在文件里链接它,最后 push 到 github 上.github 图片链接格式:(http://github.com/yourname/your-repositor ...
- yum安装Mysql-5.6
MySQL yum库提供了一个简单的和方便的方法来安装和更新MySQL相关的软件包到最新版本. MySQL yum库文档说明:http://dev.mysql.com/doc/mysql-yum-re ...
- Master和worker模式
让和hadoop的设计思想是一样的,Master负责分配任务和获取任务的结果,worker是真正处理业务逻辑的. 使用ConcurrentLikedQueue去承载所有的任务,因为会有多个worker ...
- 怎么能让json_decode解析带斜杠的字符串
比如前台一个js object:{ aa: "cc\dd"}$d = '{\"aa\": \"cc\\dd\"}';这时候用 json_d ...
- 关于URL编码(针对URL含有中文的参数)
http://www.ruanyifeng.com/blog/2010/02/url_encoding.html 一.问题的由来 URL就是网址,只要上网,就一定会用到. 一般来说,URL只能使用英文 ...
- hdu 1028 整数划分 (母函数)
假如输入44 = 4;4 = 3 + 1;4 = 2 + 2;4 = 2 + 1 + 1;4 = 1 + 1 + 1 + 1;一共5种 假如输入3 用母函数的方法就是写成(1+X+X2+X3)(1+X ...
- 在jenkins里使用SCM管理jenkinsfile
注意,这样作的前提是,插件里一定要安装pipeline和git. 设置就比较简单了. 在gitlat里生成一个演示的jenkinsfile pipeline { agent { node { labe ...
- LR检查点
LR检查点 之前使用LoadRunner工具,一直认为,在开发脚本中检查点的设置是最容易的,直到现在,有一段时间没碰LR,今天录制了一段脚本,设置了文本检查点,回放脚本后,总是报错,描述一下我设置 ...