70分求助,悬关

P5707 【深基2.例12】上学迟到

chenqile @ 2023-12-19 20:24:44

大佬看看我哪里不对了

#include <cstdio>
int main(){
    long long s, v;
    scanf("%lld %lld", &s, &v);
    int k = s/v*v==s?s/v:s/v+1;
    printf("0%d:", (470-k)/60);
    if((470-k)%60<=9) printf("0%d", (470-k)%60);
    else printf("%lld", (470-k)%60);
    return 0;
}

by pig_IG @ 2023-12-19 20:42:28

@chenqile 半夜出发?


by chenqile @ 2023-12-19 21:04:20

??@PengDave怎么变成50分了


by PengDave @ 2023-12-19 21:05:18

@chenqile 要注意前一天出发的情况

#include <cstdio>
int main(){
    long long s, v;
    scanf("%lld %lld", &s, &v);
    int k = (s%v==0)?s/v:s/v+1;
    int hm=8*60+24*60-k-10;//24*60是前一天的小时数
    if(hm>=24*60) hm-=24*60;//如果不是前一天,就减了前一天的小时数
    if(hm/60<10){
        printf("0%d:", hm/60);
    }else{
        printf("%d:",hm/60);
    }

    if(hm%60<=9) printf("0%d", hm%60);
    else printf("%d", hm%60);
    return 0;
}

by PengDave @ 2023-12-19 21:06:07

@chenqile 代码发错了


by I_Love_DS @ 2023-12-19 21:24:26

考虑前一天出发的情况

#include <bits/stdc++.h>
using namespace std;
int s,v;
int main(){
    scanf("%d%d",&s,&v);
    int k = ceil((double)s / v) + 10;
    int t = 480 + 1440;
    t -= k;
    if (t >= 1440) t -= 1440;
    if (t / 60 < 10) printf("0");
    printf("%d:",t / 60);
    if (t % 60 < 10) printf("0");
    printf("%d",t % 60);
    return 0;
}

by I_Love_DS @ 2023-12-19 21:31:45

补充说明:以下为有注释

#include <bits/stdc++.h>
using namespace std;
int s,v;
int main(){
    scanf("%d%d",&s,&v);//输入
    int k = ceil((double)s / v) + 10;//求去学校所需时间
    int t = 480 + 1440;//出发时间
    t -= k;//减
    if (t >= 1440) t -= 1440;//如果不在前一天,-1天
    if (t / 60 < 10) printf("0");//前导0
    printf("%d:",t / 60);
    if (t % 60 < 10) printf("0");//前导0
    printf("%d",t % 60);
    //结束
    return 0;
}

|