UVa1346 - Songs
2013-03-21 17:08
232 查看
JohnDoeisafamousDJand,therefore,hastheproblemofoptimizingtheplacementofsongsonhistapes.ForagiventapeandforeachsongonthattapeJohnknowsthelengthofthesongandthefrequencyofplayingthatsong.Hisproblemistorecordthesongsonthetapeinanorderthatminimizestheexpectedaccesstime.IfthesongsarerecordedintheorderS(s1),...,Ss(n)onthetapethenthefunctionthatmustbeminimizedis
ViewCode
ViewCode
#include<stdio.h> #defineMAXN0x1001B typedefstruct { intid; intlen; doublerate; }NODE; NODEa[MAXN]; voidqsort(intl,intr) { inti,j; NODEmid; NODEtemp; i=l; j=r; mid=a[(l+r)/2]; while(i<=j) { while(a[i].len*mid.rate<mid.len*a[i].rate)i++; while(a[j].len*mid.rate>mid.len*a[j].rate)j--; if(i<=j) { temp=a[i]; a[i]=a[j]; a[j]=temp; i++; j--; } } if(i<r)qsort(i,r); if(j>l)qsort(l,j); } intn,m; intmain(void) { inti; while(scanf("%d",&n)==1) { for(i=0;i<n;i++) scanf("%d%d%lf",&a[i].id,&a[i].len,&a[i].rate); scanf("%d",&m); qsort(0,n-1); printf("%d\n",a[m-1].id); } return0; }
相关文章推荐
- Songs (UVA-1346)贪心
- UVA - 1346 Songs 贪心
- uva 1346 Songs
- 【UVA】1346 - Songs(贪心)
- UVA 1346 - Songs (贪心)
- uva 1346 - Songs(贪心)
- UVA - 1346 Songs 简单贪心
- UVa 1346 - Songs
- UVA 1346 - Songs
- UVa 1346 Songs (贪心好题)
- uva 1346 - Songs(贪心)
- UVa 1346 - Songs
- uva 1346 Songs(贪心)
- uva 1346 - Songs(贪心)
- 1346 - Songs (贪心)
- UVALive - 3303 Songs
- uva1346(排序)
- 1346 - Songs (贪心)
- uva 1346(贪心)
- uva 100 The 3n+1 problem