AT_cf_2015_relay_e 反転時計 的题解

该编程题描述了一个时钟翻转功能,允许在正午前将时间逆时针旋转180度。时针逆时针转180度相当于减少6小时,分针减少30分钟。给定两个时间,需要判断翻转后的时间是否不晚于原时间。代码示例中展示了如何用C++解决此问题。

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:岛国题目输出后要加换行。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值