60分求助

B2046 骑车与走路

hcodm @ 2024-06-12 16:51:25

试了很多次还是过不了

再来看看我60分的代码

#include<bits/stdc++.h>
using namespace std;
int main(){
    int max_bike=50,max_walk=0,n;
    double a,b;
    cin>>n;
    while(a<=n&&b<=n){
        a+=1.2;
        b+=3.0;
        max_bike++;
        max_walk++;
    }
    if(max_walk<max_bike){
        cout<<"Bike";
    }else if(max_walk>max_bike){
        cout<<"Walk";
    }
    else cout<<"All";
}

虽然样例没过

哪个大佬帮帮我


by LHM_zs @ 2024-06-12 17:03:03

@hcodm

#include<bits/stdc++.h>
using namespace std;
int a;
double b,c;
int main(){      
    cin>>a;
    b=a/1.2,c=a/3.0+27.0+23.0;
    if(c<b) cout<<"Bike";
    else if(b>c)cout<<"Walk";
    else cout<<"All";
    return 0;
}

by hcodm @ 2024-06-12 17:09:22

@LHM_zs还是60分


by Liu_Zi_Xiao @ 2024-06-12 17:40:41

@hcodm 可以用函数思想

设路程(输入)为x,走路需y1秒,骑车需y2秒,则有:

y1=x/1.2 , y2=x/3+50

转换为代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    double x;
    cin>>x;
    double y1=x/1.2,y2=x/3+50;
    if(y1>y2) cout<<"Bike";
    else if(y1<y2) cout<<"Walk";
    else cout<<"All";
    return 0;
} 

结果在这里


by hcodm @ 2024-06-13 16:07:55

@Liu_Zi_Xiao

谢谢大佬,又过了 为什么要说又


|