HDU 2570 迷瘴

http://acm.hdu.edu.cn/showproblem.php?pid=2570

这道题WA了十多次,百思不得其解,百度了一组数据

1
2 1 6
5 7

实数运算一定要修正误差

View Code
#include <stdio.h>
#include <stdlib.h>
int cmp(const void*a,const void*b)
{
return *(int*)a-*(int*)b;
}
int main()
{
int t,n,cnt;
int v,w,p[200];
int i,j,f;
double q,rz,ry;
scanf("%d",&t);
while(t--)
{
rz=ry=0;
f=cnt=0;
scanf("%d%d%d",&n,&v,&w);
for(i=0;i<n;i++)
scanf("%d",&p[i]);
qsort(p,n,sizeof(int),cmp);
if(p[0]>w)printf("0 0.00\n");
else
{
while(1)
{
rz+=0.01*p[cnt++]*v;
ry+=v;
q=rz/ry;
if(q>((0.01*w)+1e-10)&&q>((0.01*w)-1e-10)){f=1;break;}
if(cnt==n)break;
}
if(f)
{
ry-=v;
rz-=p[cnt-1]*0.01*v;
}
q=rz/ry;
printf("%.0lf %.2lf\n",ry,q);
}
}
return 0;
}


 

原文地址:https://www.cnblogs.com/xiaohongmao/p/2431842.html