Problem Description
从a点b分到s点t分时针和分针重合多少次?
Input
有多组数据,每组1行4个数 a,b,s,t. 1<=a,s <=12, 0<=b,t<60. 0 0 0 0结束.
Output
参看Sample output
Sample Input
12 50 1 2 3 8 3 20 2 45 11 0 11 0 3 20 1 2 12 50 3 20 3 8 0 0 0 0
Sample Output
0 1 8 4 11 10
相当于智力题了。
不做习惯还真不太容易做出来,看来考智力的题目都扯淡,做过,习惯这种思维才是王道。
关键:
思考分针,看看分针可以在这个时间段内循环多少圈,每循环一圈就是相遇一次。
不过要仔细计算,否则会答案错误的,就差那么一圈地WA,气死人。
#include <cstdio>
class ClockMeets_1
{
int Vm, Vh;
int a, b, s, t;
int counting()
{
int v = Vm - Vh;
int s1 = (a*60 + b) * v;
int s2 = (s*60 + t) * v;
int times = s2 / 720 - s1 / 720;//可以走多少圈,和已经走多少圈相减
if (s1 == 0) times++;//00:00出发的时候,加上出发时相遇
return times;
}
public:
ClockMeets_1() : Vh(1), Vm(12)
{
while (scanf("%d %d %d %d", &a, &b, &s, &t) && (a || b || s || t))
{
if(a>s || (a==s && b>=t)) s += 12;
printf("%d\n", counting());
}
}
};