大佬们求助:为什么这个不能过,而另一个能过

P1426 小鱼会有危险吗

//以下是能AC的代码 //二者难道不是等价的吗? #include<stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int main() { long double s,x,v,l; long long flag=0; scanf("%Lf%Lf",&s,&x); v=7; l=0; while (l<(s-x)) { l+=v; v=v*0.98000; } l+=v; if (l<=(s+x)) { flag=1; } else { flag=0; } if (1==flag) { printf("y\n"); } else { printf("n\n"); } return 0; }
by 粤若稽古 @ 2018-12-18 13:07:40


//以下是能AC的代码(重发一下,3个月了,还是不太懂一些细节的规则……) //二者难道不是等价的吗? #include<stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int main() { long double s,x,v,l; long long flag=0; scanf("%Lf%Lf",&s,&x); v=7; l=0; while (l<(s-x)) { l+=v; v=v*0.98000; } l+=v; if (l<=(s+x)) { flag=1; } else { flag=0; } if (1==flag) { printf("y\n"); } else { printf("n\n"); } return 0; }
by 粤若稽古 @ 2018-12-18 13:08:43


希望更丰富的展现?使用Markdown
by VenusM1nT @ 2018-12-18 13:11:37


# 你的: ```cpp #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> long double func(long double t) { long double s,i=0; for(i=1,s=1;i<=t;i++) { s=s*0.9800; } return 350.0000*(1-s); } int main() { long double t=0,s,x,flag=0; scanf("%lf%lf",&s,&x); while(func(t)<=(s-x)) { t++; } if(func(t+1)<=(s+x)) { flag=1; } else { flag=0; } if(1==flag) { printf("y\n"); } else { printf("n\n"); } return 0; } ``` # AC: ```cpp #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main() { long double s,x,v,l; long long flag=0; scanf("%Lf%Lf",&s,&x); v=7; l=0; while(l<(s-x)) { l+=v; v=v*0.98000; } l+=v; if(l<=(s+x)) { flag=1; } else { flag=0; } if(1==flag) { printf("y\n"); } else { printf("n\n"); } return 0; } ```
by 我是一个蒟蒻 @ 2018-12-18 13:37:15


@[萌萌的蒟蒻](/space/show?uid=133063)
by 我是一个蒟蒻 @ 2018-12-18 13:37:56


@[我是一个蒟蒻](/space/show?uid=154952) 两个都是我自己写的, 只不过是写后一个能过,然后想写给函数“美化” (作死),然后就过不了了……
by 粤若稽古 @ 2018-12-18 16:35:51


@[我是一个蒟蒻](/space/show?uid=154952) 萌新不太会用洛谷,刚刚才看到。 还是要谢谢你哦
by 粤若稽古 @ 2018-12-28 17:12:21


|