UvaLive 6664 Clock Hands

Links: http://vjudge.net/problem/viewProblem.action?id=49409

Meaning of the questions: can record to a strange table within hours of N (Table life of 12-hour time).

And gives a current time, the seconds happens to find the next occurrence of the situation in time of hour and minute hands in the middle of the output integer hour and minute of the second score indicates also practical.

Ideas:

First calculate the current rotational angle of the seconds hour and minute hands. Referred to the total angle of the dial 1.



After the set time has elapsed ss, required in the case of the title appears.

It can list the formula:


The above brought, simplification was:


We want to take a case of k = 1 time. When k = 1 is assumed that three needles overlap exactly, it takes when k = 2, to take up from small to large. Among small problem lies in how to score in seconds.

Code:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<ctype.h>
#include<algorithm>
#include<string>
#define PI acos(-1.0)
#define maxn 10005
#define INF 0x7fffffff
typedef long long ll;
using namespace std;
int gcd(int x,int y)
{
    return y?

gcd(y,x%y):x; } int main() { int H,h,m,s,ans_h,ans_m,ans_s; while(scanf("%d%d%d%d",&H,&h,&m,&s)&&!(!H&&!h&&!m&&!s)) { int hh=3600*h+60*m+s; int mm=60*m*H+s*H; int ss=60*s*H; int K=3600*H; int cmp=mm+hh-ss*2; cmp=(cmp%K+K)%K; int aa=119*H-1; while(1) { int a=aa; int c=cmp; int t=gcd(a,c); a/=t;c/=t; ans_h=(h+(m+(a*s+c)/(a*60))/60)%H; ans_m=(m+(a*s+c)/(a*60))%60; ans_s=(a*s+c)%(a*60); if((3600*ans_h+60*ans_m)*a+ans_s!=60*ans_m*a*H+ans_s*H) { printf("%d %d %d %d\n",ans_h,ans_m,ans_s,a); break; } cmp+=K; } } return 0; }



Guess you like

Origin www.cnblogs.com/ldxsuanfa/p/10954634.html