优化了一点点。
2026-07-02 20:57:40
发布于:浙江
28阅读
0回复
0点赞
1.50MB是我的极限。。。
printf 和 scanf 的执行效率更高,在格式化输出上(好像)更灵活。
n和m是int类型,占用4字节(一般情况)
total是double类型,占用8字节
#include<cstdio>
int main(){
int n,m;
double total;//总费用
scanf("%d %d",&n,&m);
if(n>2){
total=(n-2)*3+m*0.5;
}else{
total=m*0.5;
}
printf("%.1f\n",total);
//同理,这也要保留
return 0;
}
或者
#include<stdio.h>
int main(){
int n,m;
scanf("%d %d",&n,&m);
double total=(n>2)?(n-2)*3+m*0.5:m*0.5;
//根据 n 是否大于 2 来计算停车费用,与充电费用相加得到总费用。
printf("%.1f\n",total);
//这里要保留小数
return 0;
}
这里空空如也


有帮助,赞一个