大意:鞋匠接收了许多订单,有些鞋子有一定的修理期限,超过了这个期限就会罚款,让你求出最少赔款的方案,如果有多个相同的,请按输入的顺序从小到大输出。

 

思路:可以证明是简单的贪心,即时间越早,而罚款数越大则越先修。按照fine/cost排序即可。

 

CODE:

 

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

#define MAXN 1001

struct node
{
    int cost, fine;
    double price;
    int order;
}a[MAXN];

int cmp(const node &a, const node &b)
{
    if(a.price != b.price) return a.price > b.price;
    else return a.order < b.order;
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n;
        int order = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++)
        {
            scanf("%d%d", &a[i].cost, &a[i].fine);
            a[i].price = a[i].fine*1.0/a[i].cost;
            a[i].order = ++order;
        }
        sort(a, a+n, cmp);
        for(int i = 0; i < n; i++)
        {
            printf(i!=n-1?"%d ":"%d\n", a[i].order);
        }
        if(T) printf("\n");
    }
    return 0;
}

 

 

posted on 2012-10-15 18:06  有间博客  阅读(415)  评论(0编辑  收藏  举报