作业帮 > 综合 > 作业

一道c语言题,老是Output Limit Exceed,不知为何,

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/30 08:33:34
一道c语言题,老是Output Limit Exceed,不知为何,
Description
挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一下;再滴三滴,..,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?
Input
输入数据包含多个测试实例,每个实例占一行,由VUL和D组成,其中 0 < D < VUL < 5000.
Output
对于每组测试数据,请输出挂完盐水需要的时间,每个实例的输出占一行.
Sample Input
10 1
Sample Output
13
#include
int main()
{
int d,vol;
int f(int,int);
while (scanf ("%d%d",&vol,&d)!=EOF)
{
if (vol=5000||d=5000)
break;
printf ("%d\n",f(vol,d));
}
return 0;
}
int f(int vol,int d)
{
int i,s=0,t=0;
for (i=1;s
while (scanf ("%d%d",&vol,&d)!=EOF)
改成
while (scanf ("%d%d",&vol,&d)==2)
再问: 改了之后运行还是可以的,但传到oj上成wrong answer了。
再答: WA是肯定的了。你试试这个Case Sample Input 2 1 Sample Output 3 //用int不靠谱, 改用double吧 #include #include int main() { double d,vol; int f(double,double); while (scanf("%lf%lf",&vol,&d)==2) { printf ("%d\n",f(vol,d)); } return 0; } int f(double vol,double d) { int t=0,i=1, drop; double temp=vol; temp-=d; while(temp>0) { i++; t++; temp-=d*i; } drop = vol/d; if(fabs(vol/d-drop)>1e-6) drop++; return drop+t; }
再问: 重新改了一下,还是wa,能再帮我看一下吗,谢谢了。