HDOJ--1006
来源:互联网 发布:ug轮廓3d倒角编程技巧 编辑:程序博客网 时间:2024/04/30 10:23
Tick and Tick
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15669 Accepted Submission(s): 3713
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
这题我刚刚看见的时候感觉看不懂,有点不知所云,细读题发现这是一道秒,分,时针的追击问题,既然如此肯定就会涉及到角速度的问题。不得不说这题确实需要一定的数学能力,想了好久也做了好久。有ACM竞赛题的味道在里面。
关键:
①秒针6°/s;分针0.1°/s;时针1/120°/s。
②秒分时之间的角度关系:
秒:6*s
分:6*m+s*0.1;
时:30*h+0.5*m+s*1/120。
接下来就是边想边写代码了。以下是我的AC代码:
//杭电acm--1006//Tick and Tick#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#define V_SEC 6.0#define V_MIN 0.1#define V_HOU 1.0/120.0#define A_SEC s*6#define A_MIN m*6+s*0.1#define A_HOU h*30+m*0.5+s/120.0using namespace std;struct interval{ double l; double r; };double Angle;int s=0;interval solve(double v,double a){ interval p; if(v>0) { p.l=(Angle-a)/v; p.r=(360-Angle-a)/v; } else { p.l=(360-Angle-a)/v; p.r=(Angle-a)/v; } if(p.l<0)p.l=0; if(p.r>60)p.r=60; if(p.l>=p.r)p.l=p.r=0; return p;}interval intersection(interval a,interval b){ interval p; p.l=max(a.l,b.l); p.r=min(a.r,b.r); if(p.l>=p.r)p.l=p.r=0; return p;}double happytime(int h,int m){ double v_diff; double a_diff; interval str[3][2]; interval s1; v_diff=V_HOU-V_MIN; a_diff=A_HOU-A_MIN; str[0][0]=solve(v_diff,a_diff); str[0][1]=solve(-v_diff,-a_diff); v_diff=V_MIN-V_SEC; a_diff=A_MIN-A_SEC; str[1][0]=solve(v_diff,a_diff); str[1][1]=solve(-v_diff,-a_diff); v_diff=V_HOU-V_SEC; a_diff=A_HOU-A_SEC; str[2][0]=solve(v_diff,a_diff); str[2][1]=solve(-v_diff,-a_diff); double result=0; for(int i=0;i<2;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) { s1=intersection(intersection(str[0][i],str[1][j]),str[2][k]); result+=s1.r-s1.l; } return result;}int main(){ int h,m; while(scanf("%lf",&Angle)==1 && Angle!=-1) { double result=0; for(h=0;h<12;h++) { for(m=0;m<60;m++) { result+=happytime(h,m); } } printf("%.3lf\n",result*100/43200); } return 0;}
0 0
- HDOJ--1006
- N! HDoj 1006
- hdoj【1006】【未完待续】
- HDOJ
- hdoj
- hdoj
- HDOJ
- HDOJ 1006 Tick and Tick
- HDOJ 1006 Tick and Tick
- poj 1006 && hdoj 1370 Biorhythms 【CRT】
- hdoj 1568 && hdoj 5344 && hdoj 5444
- 【数论】 HDOJ 1370 && POJ 1006 && ZOJ 1160 Biorhythms
- HDOJ 2176
- Hdoj--1272
- hdoj 1003
- hdoj 1005
- hdoj 1030
- hdoj 2154
- [Vim]
- leetcode -- Jump Game-- 重点--Greedy
- Xcod 常见错误
- js----创建节点和插入节点
- Python——OOP(2)
- HDOJ--1006
- ContentProvider启动时机问题简记
- ZOJ 2358 2481
- HDU 1242 Rescue
- 【Android 进阶(一)】Android MVP框架实现过程
- 单调队列 hdu3401 Trade
- R语言--tapply,sapply(因子和列表的操作)
- IOS中5种传值方式详解(属性、Block代码块、代理、单例、通知)
- javascript脚本从载入浏览器到显示执行的过程解析