[恢]hdu 2187
2011-12-16 22:36:47
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2187
题意:中文,不说了。
mark:1wa,莫名其妙地多拍了一个return0在循环里,2B了。
代码:
# include <stdio.h>
# include <stdlib.h>
typedef struct node{
int p, m ;
}node ;
node a[1010] ;
int cmp(const void *a, const void *b)
{
node* p = (node*)a, *q = (node*)b ;
return p->p - q->p ;
}
int main ()
{
int i, T, n, m ;
double sum ;
scanf ("%d", &T) ;
while (T--)
{
scanf ("%d%d", &m, &n) ;
for (i = 0 ; i < n ; i++)
scanf ("%d%d", &a[i].p, &a[i].m) ;
qsort(a,n,sizeof(node),cmp) ;
sum = 0 ;
for(i = 0 ; i < n ; i++)
{
if (m >= a[i].p * a[i].m)
{
sum += a[i].m ;
m -= a[i].p * a[i].m ;
}
else
{
sum += 1.0*m/a[i].p;
break ;
}
}
printf ("%.2lf\n", sum) ;
}
return 0 ;
}
[ Copy to Clipboard ] [ Save to File]