码迷,mamicode.com
首页 > 其他好文 > 详细

【HDU】5182 PM2.5

时间:2015-03-08 06:40:16      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

理解好排序的方式就行。

差值不一样,降序

差值一样,按照第二个数值升序

差值一样并且第二个数值也一样,按照id进行升序

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <set>
using namespace std;


#define read() freopen("in.txt", "r", stdin)
#define write() freopen("out.txt", "w", stdout)
#define rep( i , a , b ) for ( int i = ( a ) ; i <  ( b ) ; ++ i )  
#define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i ) 
#define clr( a , x ) memset ( a , x , sizeof a )  
#define cpy( a , x ) memcpy ( a , x , sizeof a ) 
#define _max(a,b) ((a>b)?(a):(b))
#define _min(a,b) ((a<b)?(a):(b))
#define LL long long 
const int maxNumber=10002;

/*int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
inline int lcm(int a,int b)
{
	return a/gcd(a,b)*b;
}*/
struct pm
{
	int id;
	int num1;
	int num2;

};
pm city[233];

int cmp(pm a,pm b)
{
	if (a.num1-a.num2 == b.num1-b.num2 && a.num2 == b.num2)
	{
		return a.id < b.id;
	}
	if (a.num1-a.num2 == b.num1-b.num2)
	{
		return a.num2 < b.num2;
	}
	return a.num1 - a.num2 > b.num1 - b.num2;
}
int main()
{
	//read();
	int n;
	while(cin>>n)
	{
		for (int i = 0; i < n; ++i)
		{
			scanf("%d%d",&city[i].num1,&city[i].num2);
			city[i].id = i;
		}
		sort(city,city+n,cmp);
		for (int i = 0; i < n; ++i)
		{
			if (i == n - 1)
			{
				printf("%d\n",city[i].id );

			}else
			{
				printf("%d ",city[i].id );
			}
		}
	}
    return 0;
   
}

  

【HDU】5182 PM2.5

标签:

原文地址:http://www.cnblogs.com/acmsummer/p/4321249.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!