• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

(贪心5.2.1)UVA 10026 Shoemaker's Problem(利用数据有序化来进行贪心选择)

/*
 * UVA_10026.cpp
 *
 *  Created on: 2013年10月10日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 1010;
struct job{
	double a;
	int num;
}p[maxn];

bool cmp(job x, job y){
	if(x.a > y.a || (x.a == y.a && x.num < y.num)){
		return true;
	}

	return false;
}

int main(){
	int t;
	scanf("%d",&t);
	int counter = 1;
	while(t--){
		int n;
		scanf("%d",&n);

		int i;
		for(i = 1 ; i <= n ; ++i){
			double a1,a2;
			scanf("%lf%lf",&a1,&a2);
			p[i].a = a2/a1;
			p[i].num = i;
		}

		sort(p+1,p+1+n,cmp);

		if(counter > 1){
			printf("\n");
		}
		for(i = 1 ; i < n ; ++i){
			printf("%d ",p[i].num);
		}

		printf("%d\n",p[n].num);

		counter++;
	}

	return 0;
}


posted @ 2013-10-10 21:32  Class Xman  阅读(163)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3