abssortpow1145145 @ 2024-10-08 21:29:36
using namespace std;
int main()
{
int b;
cin >> b;
double a=0.0;
for(int i=1;i<=b;i++)
{
if(i<150)
{
a+=0.4463;
printf("%.4lf\n",a);
}
else if(i>=151 && i<=400)
{
a+=0.4663;
printf("%.4lf\n",a);
}
else if(i>400)
{
a+=0.5663;
printf("%.4lf\n",a);
}
}
printf("%.4lf",a);
return 0;
}
by abssortpow1145145 @ 2024-10-08 21:30:38
不用管头文件
by abssortpow1145145 @ 2024-10-08 21:33:15
不用管输出(那是验证)
by chenhouye @ 2024-10-08 21:37:10
如果i等于150怎么办?
第一个判断条件应是
if(i<=150){
...
}
@yuanhongrui0918
by abssortpow1145145 @ 2024-10-08 21:41:34
@chenhouye
using namespace
std;
int main()
{
int b;
cin >> b;
double a=0.0;
for(int i=1;i<=b;i++)
{
if(i<=150)
{
a+=0.4463;
}
else if(i>=151 && i<=400)
{
a+=0.4663;
}
else if(i>400)
{
a+=0.5663;
}
}
printf("%.1lf",a);
return 0;
}
0分 ??
by chenhouye @ 2024-10-08 21:43:41
@yuanhongrui0918
我又看了一便,你没认真读题,题目要求保留一位小数输出
by abssortpow1145145 @ 2024-10-08 21:53:06
printf("%.1lf",a); @chenhouye 我保了一位!
by abssortpow1145145 @ 2024-10-08 21:59:40
#include <bits/stdc++.h>
using namespace std;
int main()
{
int b;
cin >> b;
if(b<=150)
{
printf("%.1lf",b*0.4463);
}
else if(b>=151 && b<=400)
{
printf("%.1lf",(150*0.4463)+((b-150)*0.4663));
}
else if(b>400)
{
printf("%.1lf",(150*0.4463)+(250*0.4663)+(b-400)*0.5663);
}
return 0;
}
by chenhouye @ 2024-10-08 22:17:08
#include<bits/stdc++.h>
using namespace std;
double slove1(int c){
int b=c;
double a=0.0;
for(int i=1;i<=b;i++)
{
if(i<=150)
{
a+=0.4463;
}
else if(i>=151 && i<=400)
{
a+=0.4663;
}
else if(i>400)
{
a+=0.5663;
}
}
return a;
}
double slove2(int c){
int x=c,t=0,t1=0;
double ans=0;
if(x<150){
ans=x*0.4463;
}
else{
ans+=150*0.4463;
t=x-150;
if(x<=400){
ans+=t*0.4663;
}
else{
ans+=250*0.4663;
t1=x-400;
ans+=t1*0.5663;
}
}
return ans;
}
int main()
{
//cout<<slove1(19)<<endl<<slove2(19);
for(int i=1;i<=1000;i++){
double a=slove1(i),b=slove2(i);
if(a==b) continue;
cout<<i<<endl<<slove1(i)<<endl<<slove2(i)<<endl<<endl;
}
return 0;
}
@yuanhongrui0918
slove1是你的原先做法
slove2是我的AC做法
结果这样一核对下来发现一件惊人的事情:就是当测试数据为19时,slove1&slove2的结果都是8.4797,但程序竟然认为
8.4794!=8.4797
这太奇怪了,你试试我的方法吧
(这件事走近科学来了也得拍三期)
by abssortpow1145145 @ 2024-10-08 22:20:45
@chenhouye 你这个方法我已经试过了。确实是AC
by chenhouye @ 2024-10-08 22:31:04
@yuanhongrui0918
666那就这么办吧