30分

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

@[W3240663127](/user/820456) ``` #include<bits/stdc++.h> using namespace std; signed main() { int s,u,t; scanf ("%d%d",&s,&u); if ( s%u == 0) { t=s/u; t+=9; } else { t=s/u; t+=10; } int h; int m; h = 7; m = 59; while (t != 0) { if (m != 0) { m--; } else { if (h!=0) { h--; m=59; } else { h=23; m=59; } } t--; } int a,b; int c,d; a = h/10; b = h-(10*(h/10)); c = m/10; d = m-(10*(m/10)); printf ("%d%d:%d%d",a,b,c,d); return 0; } ```
by SZH0523 @ 2022-10-07 17:54:03


@[W3240663127](/user/820456) ```cpp #include <iostream> #include <cmath> using namespace std; int main() { int u, v, a, h, m; cin >> u >> v; a=ceil(1.0*u/v) + 10; h=ceil(1.0*a/60), m=60-(a-1)%60-1; //cout << h << " "; if(h <= 8) { h=8-h; if(h<10) cout << "0"; cout << h << ":"; } else if(h > 8) { h=24-(h-8); if(h<10) cout << "0"; cout << h << ":"; } if(m < 10) cout << "0"; cout << m << endl; return 0; } ``` 我的代码
by zqyha @ 2022-10-07 17:54:23


@[Yu0215](/user/610096) dalao你好,其他都看懂了,感觉你写的比我真的好很多,但是有一处我不明白,h=ceil(1.0*a/60), m=60-(a-1)%60-1;为什么h还要向上取整,m最后为什么还要再减一呢
by W3240663127 @ 2022-10-07 19:18:46


@[W3240663127](/user/820456) 我先声明抱歉,昨天浏览器没时间了,所以没有上线。 第一处向上取整,我觉得你可以自己研究一下,这里向上取整只是为了后面做差方便一点 第二处,题目说了需要提前一分钟,所以时间再减去1(提前)
by zqyha @ 2022-10-08 17:19:22


|