uva 10339 - Watching Watches(数论)

942 篇文章 2 订阅
202 篇文章 0 订阅

题目链接:uva 10339 - Watching Watches


题目大意:有两个表,每天都会慢一点时间,给出每天慢得秒数,问说下一次重合的时刻。


解题思路:时刻重合也就是说整整差了一周,一周是12小时,用12小时的秒数除以两个表的相差那就是需要多少天的时间后重合,知道了需要多少天*每一天某个表走的时间(注意要减去少走的时间)即使答案,化成时间的格式即可,注意0时显示成12时。


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

const int R = 12 * 60 * 60;
const int D = 24 * 60 * 60;

int k, m;

int main () {
	while (scanf("%d%d", &k, &m) == 2) {
		int d = abs(k - m);
		if (d == 0) {
			printf("%d %d 12:00\n", k, m);
			continue;	
		}

		double p = R*1.0/d;
		int t = (int)(p * (D - k)/60.0 + 0.5)%D;

		int h = t/60;
		h %= 12;
		if (h == 0) h = 12;
		int f = t%60;
		printf("%d %d %02d:%02d\n", k, m, h, f);
	}
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值