uva 10026 Shoemaker's Problem

时间:2023-12-09 18:53:49

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=967

对价钱与天数比例排序,贪心即可。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 2000
using namespace std; int n;
struct node
{
int num;
double pay;
int d;
bool operator <(const node &a)const
{
return (pay>a.pay)||(pay==a.pay&&num<a.num);
}
}p[maxn]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
int x,y;
scanf("%d%d",&x,&y);
p[i].num=i;
p[i].pay=(double)(y*1.0/x);
p[i].d=x;
}
sort(p+,p++n);
for(int i=; i<=n; i++)
{
if(i==)
{
printf("%d",p[i].num);
}
else printf(" %d",p[i].num);
}
printf("\n");
if(t) printf("\n");
}
}