HDU 1006 模拟
Tick and Tick
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20120 Accepted Submission(s): 5262
120
90
-1
0.000
6.251
三个指针走的角速度:
秒针速度S = 6°/s,分针速度M = (1/10)°/s,时针速度H = (1/120)°/s
这三个指针两两之间的相对速度差为:
秒时相差S_H = (719/120)°/s,秒分相差S_M = (59/10)°/s,分时相差M_H = (120/11)°/s
相差一度需要的时间为
秒时相差SH = (120/719)s/度,秒分相差SM = (10/59)s/度,分时相差MH = (120/11)s/度
相差360°需要的时间为
秒时相差tSH = 43200.0/719,秒分相差tSM = 3600.0/59,分时相差tMH = 43200.0/11
算出两两指针在43200s(12小时)内满足条件时间的区间的交集。
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
///秒针角速度 6度/s, 分针0.1度/s,时针1/120度/s
const double sh = 719.0/120 , sm = 59.0/10, mh = 11.0/120;///三个指针两两相对角速度。
const double tsh = 43200.0 / 719, tsm = 3600.0 / 59, tmh = 43200.0 / 11;///三个指针两两相差360度所需的时间。
///将相对角速度变成周期。(即两针间需要多久出现夹角的循环)
/// 同样可求得三个周期的最小公倍数为 43200 秒,即12小时,
double max1(double a, double b, double c)
{
return max(a, max(b, c));
}
double min1(double a, double b, double c)
{
return min(a, min(b, c));
}
int main(void)
{
int D;
while(scanf("%d", &D), D != -1)
{
double bsh, bsm, bmh, esh, esm, emh, total, beginn, endd;
///第一次满足条件的时间。(开始时间)
bsh = D / sh;
bsm = D / sm;
bmh = D / mh;
///第一次出现不满足条件的时间。(结束时间)
esh = (360 - D) / sh;
esm = (360 - D) / sm;
emh = (360 - D) / mh;
total = 0;
for(double bt1 = bsh, et1 = esh; et1<= 43200.000001; bt1 += tsh, et1 += tsh)
{
for(double bt2 = bsm, et2 = esm; et2 <= 43200.000001; bt2 += tsm, et2 += tsm)
{
///判断是否有交集。
if(bt2 > et1)
break;
if(et2 < bt1)
continue;
for(double bt3 = bmh, et3 = emh; et3 <= 43200.000001; bt3 += tmh, et3 += tmh)
{
if(bt3 > et1 || bt3 > et2)
break;
if(et3 < bt1 || et3 < bt2)
continue;
beginn = max1(bt1, bt2, bt3);
endd = min1(et1, et2, et3);
total += (endd - beginn);
}
}
}
printf("%.3f\n", total / 432);
}
return 0;
}
最新文章
- 简述block
- Facebook的体系结构分析---外文转载
- JS_ECMA基本语法中的几种封装的小函数-1
- HDU 4421 Bit Magic (图论-2SAT)
- 高效开发 Android App 的 10 个建议(转)
- Dev GridControl导出
- PHP 中的 9 个魔术方法
- Python参数中的*和**
- php实现base64编码
- Unity CCTween UGUI 动画插件
- 使用libcurl进行文件上传
- file.go
- 向量的L2范数求导
- Git -- 使用GitHub
- 【Hadoop学习之六】MapReduce原理
- 数据结构:IO读写频繁的青睐,B树和B+树
- 【图像处理】基于OpenCV底层实现的直方图匹配
- MKAnnotationView和MKPinAnnotationView的区别
- CSS 小结笔记之三种样式表
- express 调优的一个过程和心得,不错的文章
热门文章
- 【C&;数据结构】---关于链表结构的前序插入和后序插入
- 初识runtime
- python爬虫——selenium+chrome使用代理
- python条件与循环-条件
- 添加动态输出 Adding Dynamic Output 精通ASP-NET-MVC-5-弗瑞曼 Listing 2-7
- 通过识别页面内容获得返回值判断后续执行(exists指令的用法)
- 请求参content-type的值为json,返回报错的解决方法
- influxdb+Grafana+jmeter监控搭建
- CountDownLatch CyclicBarrier和 Semaphore
- DNS隧道工具:iodine使用