uva 10339 - Watching Watches(数论)

来源:互联网 发布:会员卡管理php源码 编辑:程序博客网 时间:2024/05/18 12:03

题目链接: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
原创粉丝点击