Problem - 1006_Tick and Tick
来源:互联网 发布:微商货源网源码 编辑:程序博客网 时间:2024/06/05 19:42
Tick and Tick
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10255 Accepted Submission(s): 2879
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
012090-1
Sample Output
100.0000.0006.251
Author
PAN, Minghao
Source
ZJCPC2004
Recommend
JGShining | We have carefully selected several similar problems for you: 1007 1008 1010 1009 1011
#include<stdio.h>typedef struct{ double left,right;}Section;double d;Section s[3][2];Section Intersection(Section a,Section b){ Section s; s.left=a.left>b.left?a.left:b.left; s.right=a.right<b.right?a.right:b.right; if(s.left>s.right){ s.left=s.right; } return s;}Section setSection(double x,double y){ Section s; /** * d<=x*s+y<=360-d(s∈[0,59],s∈N) * 1.x<0 d-y<=x*s<=360-d-y * (360-d-y)/x<=s<=(d-y)/x * 2.x=0 d<=y<=360-d * d-y<=0<=360-d-y * d<=180(题设d∈[0,120]【情况可忽略】) * 3.x>0 d-y<=x*s<=360-d-y * (d-y)/x<=s<=(360-d-y)/x */ if(x<0){ s.left=(360-d-y)/x; s.right=(d-y)/x; } else{ s.left=(d-y)/x; s.right=(360-d-y)/x; } if(s.left<0){ s.left=0; } if(s.right>60){ s.right=60; } if(s.left>s.right){ s.left=s.right; } return s;}double getHappyTime(int x,int y){ double a,b,sum; Section S; int i,j,k; /** * d<=|h-m|<=360-d * h=30*x+y/2+S/120 m=6*y+S/10 * 1.h-m>=0 => a=S/120-S/10 => b=30.0*x+y/2.0-6.0*y * =-11.0/120 =30.0*x-5.5*y * 2.m-h>=0 => a'=S/10-S/120 => b'=6.0*y-(30.0*x+y/2.0) * =11.0/120=-a =-30.0*x+5.5*y=-b */ a=-11.0/120; b=30.0*x-5.5*y; s[0][0]=setSection(a,b); s[0][1]=setSection(-a,-b); /** * d<=|h-s|<=360-d * h=30*x+y/2+S/120 s=6*S * 1.h-s>=0 => a=S/120-6*S => b=30.0*x+y/2.0 * =-719.0/120 =30.0*x+0.5*y * 2.s-h>=0 => a'=6*S-S/120 => b'=-(30.0*x+y/2.0) * =719.0/120=-a =-30.0*x-0.5*y=-b */ a=-719.0/120; b=30.0*x+y/2.0; s[1][0]=setSection(a,b); s[1][1]=setSection(-a,-b); /** * d<=|m-s|<=360-d * m=6*y+S/10 s=6*S * 1.m-s>=0 => a=S/10-6*S => b=6*y * =-5.9 * 2.s-m>=0 => a'=6*S-S/10 => b'=-6*y * =5.9=-a =-b */ a=-5.9; b=6*y; s[2][0]=setSection(a,b); s[2][1]=setSection(-a,-b); for(sum=i=0;i<2;i++){ for(j=0;j<2;j++){ for(k=0;k<2;k++){ S=Intersection(Intersection(s[0][i],s[1][j]),s[2][k]); sum+=S.right-S.left; } } } return sum;}int main(){ double sum; int hr,min; while(scanf("%lf",&d)!=EOF&&d!=-1){ for(sum=hr=0;hr<12;hr++){ for(min=0;min<60;min++){ sum+=getHappyTime(hr,min); } } printf("%.3f\n",100.0*sum/(12*60*60)); } return 0;}
0 0
- Problem - 1006_Tick and Tick
- OJ problem(Tick and Tick) 1006
- 1006 tick and tick
- 1006-Tick and Tick
- HDU 1006 Tick and Tick
- HDOJ 1006 Tick and Tick
- HDU 1006 Tick and Tick
- hdu 1006 Tick and Tick
- [HDU]1006 Tick and Tick
- HDU 1006 TICk and TICK
- HDU 1006 Tick and Tick
- Hdu 1006 Tick and Tick
- HDOJ 1006 Tick and Tick
- hdu 1006 Tick and Tick
- HDU 1006 Tick and Tick
- HDU:1006 Tick and Tick
- hdu 1006 Tick and Tick
- HDU 1006 Tick and Tick
- leetcode Subsets
- CODEVS 1245 最小的N个和 堆+排序
- 字符排列问题
- hdu 1058 朴素算法和DP做法
- 厦门大学线下编程比赛第一题:求和
- Problem - 1006_Tick and Tick
- top.location.href 不兼容 火狐和谷歌浏览器。。
- java基本语法+一点点提高
- 《组播扩展OSPF》
- HDU1128
- poj 2955 Brackets(区间DP)
- jsp标签
- 东方红是东方红地方搞活动
- 1-3认识html标签