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);
}
}
相关文章推荐
- [C++]Microsoft Visual Studio (VS)2010 功能设置
- LeetCode #9 Palindrome Number
- 常见js效果——在表格中收起展开
- 文章标题
- javascript设置input编辑框光标的位置
- [C++]VisualAssistX中文注释提示错误 解决办法
- 社説 20150712 核燃料サイクル 政府の責任で軌道に乗せよ
- 项目管理工具Maven
- 字符串的应用
- 改变Ubuntu下作为桌面,下载存放位置等的默认文件夹
- [C++]Microsoft Visual Studio (VS)2010 常用快捷键大全
- 利用运行时给分类动态添加成员变量
- 社説 20150712 岩手中2生自殺 なぜSOSは届かなかったか
- 通知模式实现两个textField传值及模态视图——iOS开发
- Android从无知到有知——NO.4
- 日经社説 20150712 中ロに問われる国際秩序づくりの自覚
- UVA 11426 - GCD - Extreme (II) (数论)
- 系统上线那点事续
- Oracle-PLSQL Developer使用笔记
- 日经社説 20150712 いまこそ暴力団への資金断て