HDU 1006.Tick and Tick【11月12】【很久没写博客了】
来源:互联网 发布:如何判断mac口红真假 编辑:程序博客网 时间:2024/05/20 11:21
Tick and Tick
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
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <map>#include <algorithm>using namespace std;double MAX(double a, double b, double c){ if(a >= b && a >= c) return a; else if(b >= c) return b; else return c;}double MIN(double a, double b, double c){ if(a <= b && a <= c) return a; else if(b <= c) return b; else return c;}int main(){ double s = 360. / 60., m = 360. / 3600., h = 360. / 43200.;//角速度 double m_s = s - m, h_m = m - h, h_s = s - h;//相对较速度 //cout << m_s <<" "<< h_m <<" "<< h_s << endl; double D,x_m_s,x_h_s,x_h_m,y_m_s,y_h_s,y_h_m;//周期 double cycle_m_s = 360 / m_s; double cycle_h_m = 360 / h_m; double cycle_h_s = 360 / h_s; //cout << cycle_m_s <<" "<< cycle_h_m <<" "<< cycle_h_s << endl; while(scanf("%lf",&D) == 1 && D != -1) { //cout << D << endl; x_m_s = D / m_s;//周期内合法区间 x_h_m = D / h_m; x_h_s = D / h_s; y_m_s = (360 - D) / m_s; y_h_m = (360 - D) / h_m; y_h_s = (360 - D) / h_s; //cout << x_m_s <<" "<< y_m_s << endl; //cout << x_h_m <<" "<< y_h_m << endl; //cout << x_h_s <<" "<< y_h_s << endl; double sumtime = 0; double begintime, endtime; //寻找交集 for(double begin1 = x_m_s,end1 = y_m_s; end1 < 43200.000001; begin1 += cycle_m_s,end1 += cycle_m_s) { for(double begin2 = x_h_m,end2 = y_h_m; end2 < 43200.000001; begin2 += cycle_h_m,end2 += cycle_h_m) { if(end1 < begin2) break; if(end2 < begin1) continue; for(double begin3 = x_h_s,end3 = y_h_s; end3 < 43200.000001; begin3 += cycle_h_s,end3 += cycle_h_s) { if(begin3 > end1 || begin3 > end2) break; if(begin1 > end3 || begin2 > end3) continue; begintime = MAX(begin1, begin2, begin3); endtime = MIN(end1, end2, end3); if(endtime > begintime) sumtime += (endtime - begintime); } } } printf("%.3f\n", sumtime / 432); } return 0;}
啊····好久没写博客了····
0 0
- HDU 1006.Tick and Tick【11月12】【很久没写博客了】
- hdu-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
- 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
- HDU1006---Tick and Tick HDU(135)
- hdu 1006 Tick and Tick 时钟问题
- hdu 1006 Tick and Tick 数学+枚举
- HDU ACM 1006 Tick and Tick
- Dell 灵越 飞匣3000 笔记本 再带Win8系统改Win7系统 (U盘安装)
- 瀑布流
- php面向对象之抽象类
- HDOJ 2586 How far away ? (LCA ST算法)
- linux多播常见问题解决办法
- HDU 1006.Tick and Tick【11月12】【很久没写博客了】
- 数组
- 文件读写概要
- Linux线程池(C语言描述) - 互斥量+条件变量同步
- 有10,000个网页,其中包含有电话号码,现在需要将电话号码抽取出来并去重,应该如何设计,使用哪些技术。
- Linux 快速清空文件内容的方法。
- 一步一步写万能makefile
- Android开发之ViewPager实现多页面切换及动画效果(仿Android的Launcher效果)
- 解决国内Android SDK不能更新的问题