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 < ...
随机推荐
- linux下使用indent整理代码(代码格式化)【转】
转自:https://blog.csdn.net/jiangjingui2011/article/details/7197069 常用的设置: indent -npro -kr -i8 -ts8 -s ...
- java浅复制与深使用接口实现
1.浅复制与深复制概念⑴浅复制(浅克隆)被复制对象的所有变量都含有与原来的对象相同的值,而所有的对其他对象的引用仍然指向原来的对象.换言之,浅复制仅仅复制所考虑的对象,而不复制它所引用的对象. ⑵深复 ...
- STM8CubeMx来了
几年前出来的STM32CubeMx是众多stm32开发者的福音,大大缩短了开发者的开发周期.就在前几天,st官网宣布针对stm8的图形配置工具stm8cube横空出世. 如果你还不知道STM32Cub ...
- Eclipse中各种编码格式及设置
操作系统:Windows 10(家庭中文版) Eclipse版本:Version: Oxygen.1a Release (4.7.1a) 刚看到一篇文章,里面介绍说Ascii.Unicode是编码,而 ...
- RStdio常用快捷键
掌握常用快捷键的使用, 可以让我们的效率加倍! 下面只列举了一些最常见的快捷键, RStdio的快捷键远不止这些, 具体的可以参照这里. 无论是在控制台还是在编辑区, Tab都可以帮助我们对代码进行补 ...
- DOS命令大全(二)
一般来说dos命令都是在dos程序中进行的,如果电脑中安装有dos程序可以从开机选项中选择进入,在windows 系统中我们还可以从开始运行中输入cmd命令进入操作系统中的dos命令,如下图: 严格的 ...
- mybatis 易百练习笔记
1. session.commit() 增删改需要提交 session.close() session需要关闭 2. insert into t() values() 不用写i ...
- HDU 5115 Dire Wolf (区间DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:有一些狼,从左到右排列,每只狼有一个伤害A,还有一个伤害B.杀死一只狼的时候,会受到这 ...
- SQL Server数据库存在判断语句及系统表简介
Transact-SQL Exists Sentences--判断数据库是否存在IF EXISTS(SELECT * FROM master.sysdatabases WHERE name=N'库名' ...
- ElasticSearch实战概要
最近中美关系越来越紧张,国内经济下滑,股市一片惨淡,互联网行业越来越不景气,动不动都是跌掉几千亿市值,来写一些文档来抚慰这颗受伤的心吧... 随着互联网的发展,数据越来越重要,每个公司保存的数据也是越 ...