AT_cf_2015_relay_e 反転時計 的题解
洛谷传送门
AT传送门
题目大意
给出两个时间, h t ht ht 时 m t mt mt 分 与 h n hn hn 时 m n mn mn 分。
现在有一个时钟翻转的功能,只能在正午之前使用,即把
h
n
hn
hn 时
m
n
mn
mn 分转换到时钟上,将分针和时针分别逆时针旋转
180
180
180 度,得到一个更早的时间。如果这个时间不晚于
h
t
ht
ht 时
m
t
mt
mt 分,输出 Yes,否则输出 No。
思路
因为时针逆时针转 180 180 180 度为减少 6 6 6 小时,分针逆时针转 180 180 180 度为减少 30 30 30 分钟。所以,先将时针和分针进行相减,然后将两个时间转换为分钟,最后进行判断。
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <string>
#include <cstring>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO {
inline int read() {
register int x = 0, f = 1;
register char c = getchar();
while (c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
inline void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
}
using namespace fastIO;
int main() {
int ht, hn, mt, mn;
cin >> ht >> hn >> mt >> mn;
mn -= 30; // 分针逆时针转180°为减少30分钟
mt -= 6; // 时针逆时针转180°为减少6小时
int time1 = ht * 60 + hn; // 转化为分钟
int time2 = mt * 60 + mn; // 转化为分钟
if (time1 <= time2) cout << "Yes" << endl; // 记得换行
else cout << "No" << endl; // 记得换行
return 0;
}
PS:岛国题目输出后要加换行。
该编程题描述了一个时钟翻转功能,允许在正午前将时间逆时针旋转180度。时针逆时针转180度相当于减少6小时,分针减少30分钟。给定两个时间,需要判断翻转后的时间是否不晚于原时间。代码示例中展示了如何用C++解决此问题。

被折叠的 条评论
为什么被折叠?



