您的位置:首页 > 其它

Hdu 1006 Tick and Tick

2015-07-12 10:03 330 查看


Tick and Tick

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 14607 Accepted Submission(s): 3354



Problem Description

The three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of this and each of them would like to stay away from the other two. A hand is happy if it is at least D degrees from any of the rest.
You are to calculate how much time in a day that all the hands are happy.

Input

The input contains many test cases. Each of them has a single line with a real number D between 0 and 120, inclusively. The input is terminated with a D of -1.

Output

For each D, print in a single line the percentage of time in a day that all of the hands are happy, accurate up to 3 decimal places.

Sample Input

0
120
90
-1


Sample Output

100.000
0.000
6.251


AC代码
#include <stdio.h>

inline double Max(double a,double b, double c)

{

double tmp = a>b?a:b;

tmp = tmp>c?tmp:c;

return tmp;

}

inline double Min(double a,double b, double c)

{

double tmp = a<b?a:b;

tmp = tmp<c?tmp:c;

return tmp;

}

int main()

{

double ss,mm,hh,sm,sh,mh,tsm,tmh,tsh;

ss = 6.0, mm = 0.1, hh = 0.1/12.0;

sm = ss-mm;

mh = mm-hh;

sh = ss-hh;

tsm = 360/sm;

tmh = 360/mh;

tsh = 360/sh;

int D;

double m[3],n[3],x[3],y[3];

while(~scanf("%d",&D)){

if(D == -1) break;

x[0] = D/sm;

x[1] = D/mh;

x[2] = D/sh;

y[0] = (360.0-D)/sm;

y[1] = (360.0-D)/mh;

y[2] = (360.0-D)/sh;

double st,ed;

double ans = 0;

for(m[0]=x[0],n[0]=y[0]; m[0]<=43200; m[0]+=tsm,n[0]+=tsm){

for(m[1]=x[1],n[1]=y[1]; m[1]<=43200; m[1]+=tmh,n[1]+=tmh){

if(m[0] > n[1]) continue;

if(n[0] < m[1]) break;

for(m[2]=x[2],n[2]=y[2]; m[2]<=43200; m[2]+=tsh,n[2]+=tsh){

if(n[2]<m[1] || n[2]<m[0]) continue;

if(m[2]>n[0] || m[2]>n[1]) break;

st = Max(m[0],m[1],m[2]);

ed = Min(n[0],n[1],n[2]);

if(ed > st) ans += ed-st;

}

}

}

printf("%.3f\n",ans/432.0);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: