uva10026 - Shoemaker's Problem
大水题,,,贪心,
代码如下:
#include <cstdio> #include <cstdlib> #define M 1010 int st[M][3]; int comp(const void *a, const void *b) { int *c = (int*)a, *d = (int*)b; if(c[0]*d[1]-c[1]*d[0]!=0) return c[0]*d[1]-c[1]*d[0]; else return c[2]-d[2]; } int main () { int t, n; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i = 0; i < n; i++) {scanf("%d%d",&st[i][0],&st[i][1]); st[i][2] = i+1; } qsort(st,n,sizeof(st[0]),comp); for(int i = 0; i < n; i++) i==0?printf("%d",st[i][2]):printf(" %d",st[i][2]); if(t)printf("\n\n"); else printf("\n"); } return 0; }