HDU-Tick and Tick
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
本人实在太菜:
参考自该博主,顺便附上链接膜一波:https://blog.csdn.net/yuyanggo/article/details/45765811
解析:这道题,其实想通了也不难,甚至可以说太简单了。
时钟的时针、分针、秒针一天内的三次重合点:0:00 12:00 24:00
所以计算这道题的是时候,只需要考虑0:00到12:00即可。
设:ws 表示秒针的角速度
wm 表示分针的角速度
wh 表示时针的角速度
wsm=ws-wm 表示秒针相对于分针的角速度
wsh=ws-wh 表示秒针相对于时针的角速度
wmh=wm-wh 表示分针相对于时针的角速度
那么就有:(t1,t2,t3<=12*60*60)
360*(i-1)+d<=wsm*t1<=360*i-d
360*(j-1)+d<=wsh*t2<=360*j-d
360*(k-1)+d<=wmh*t3<=360*k-d
t1、t2、t3可取时间的交集即为答案。
具体实现如下:
用 sum 来记录happy time,以秒为单位。
1.枚举 i ,得到 t1 与 i 对应的左右界:L、R
若 L>=12*60*60 退出循环。
2.枚举 j ,得到 t2 与 j 对应的左右界:L2、R2。
此时应满足[L2,R2]∩[L,R] ≠ 空集。
3.枚举 k ,得到t3 与 k 对应的左右界:L3、R3
此时应满足[L3,R3]∩[L2,R2] ≠ 空集,则 [L3,R3]能使上述三个不等式均成立,为happy time。
sum+=R3-L3。
代码:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std;
double sum,d,wsm,wsh,wmh;
int main() {
wsm=59/10.0,wsh=719/120.0,wmh=11/120.0;
double l,r,l2,r2,l3,r3;
int i,j,k;
while(scanf("%lf",&d),d>-0.5) {
for(sum=0,i=1;; i++) {
l=(360*i-360+d)/wsm;
r=(360*i-d)/wsm;
if(l>12*60*60)break;
j=(int)((l*wsh+d)/360);
if((360*j-d)/wsh<=l)j++;
for(;; j++) {
l2=(360*j-360+d)/wsh;
r2=(360*j-d)/wsh;
if(l2<l)l2=l;
if(r2>r)r2=r;
if(l2>=r2)break;
k=(int)((l2*wmh+d)/360);
if((360*k-d)/wmh<=l2)k++;
for(;; k++) {
l3=(360*k-360+d)/wmh;
r3=(360*k-d)/wmh;
if(l3<l2)l3=l2;
if(r3>r2)r3=r2;
if(l3>=r3)break;
sum+=r3-l3;
}
}
}
printf("%.3lf\n",sum/(12*60*60)*100);
}
return 0;
}
HDU-Tick and Tick的更多相关文章
- HDU 1006 Tick and Tick(时钟,分钟,秒钟角度问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 1006 Tick and Tick 时钟指针问题
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1006 Tick and Tick 有技巧的暴力
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1006 Tick and Tick
Tick and Tick Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu1006 Tick and Tick
原题链接 Tick and Tick 题意 计算时针.分针.秒针24小时之内三个指针之间相差大于等于n度一天内所占百分比. 思路 每隔12小时时针.分针.秒针全部指向0,那么只需要计算12小时内的百分 ...
- HDU 1006 Tick and Tick 解不等式解法
一開始思考的时候认为好难的题目,由于感觉非常多情况.不知道从何入手. 想通了就不难了. 能够转化为一个利用速度建立不等式.然后解不等式的问题. 建立速度,路程,时间的模型例如以下: /******** ...
- [ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]
Problem Description The three hands of the clock are rotating every second and meeting each other ma ...
- 1006 Tick and Tick
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题意: 24小时中,三个指针之间超过某个度数的时间占所有时间的百分比是多少. 思路:主要是物理和数学 ...
- Tick and Tick
The three hands of the clock are rotating every second and meeting each other many times everyday. F ...
- hdu_1006 Tick and Tick(暴力模拟)
hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...
随机推荐
- springboot 使用DruidDataSource 数据源
一.添加依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</art ...
- Ajax 提交图片
话不多说,直接上代码 页面部分 <form id="form1" enctype="multipart/form-data"> id_token: ...
- ios wkwebview didReceiveAuthenticationChallenge crash解决
//需要响应身份验证时调用 同样在block中需要传入用户身份凭证 //现在就是不进行https验证了 然后就闪退不了了 - (void)webView:(WKWebView *)webView di ...
- 016_go语言中的递归
代码演示 package main import "fmt" func fact(n int) int { if n == 0 { return 1 } return n * fa ...
- SpringMvc接收multipart/form-data 传输的数据 及 PostMan各类数据类型的区别
前段时间遇到一个问题,在spring mvc 服务端接收post请求时,通过html 表单提交的时候,服务端能够接收到参数的值.但是使用httpclient4.3构造post请求,却无法接收到参数的值 ...
- Web接口测试理论知识分享
首先谈下接口的定义分为2类,程序接口和协议接口 1.程序模块接口,具体到程序中就是提供了输入输出的类 方法,我们可以通过传入不同的参数,来验证程序接口的功能 2.协议接口 比如HTTP/SOAP协议 ...
- axios的post请求返回状态码400
设置拦截 axios.interceptors.request.use((config) => { if (config.method === 'post') { if (!config.isF ...
- java流程控制语句switch
switch 条件语句也是一种很常用的选择语句,它和if条件语句不同,它只能针对某个表达 式的值作出判断,从而决定程序执行哪一段代码. 格式: switch (表达式){ case 目标值1: 执行语 ...
- C#LeetCode刷题之#811-子域名访问计数(Subdomain Visit Count)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3814 访问. 一个网站域名,如"discuss.lee ...
- 详解POW工作量证明原理
原文地址 来自 微信公众号 区块链大师 POW工作量证明(英文全称为Proof of Work)早在比特币出现之前就已经有人探索,常见的是利用HASH运算的复杂度进行CPU运算实现工作量确定,当然你 ...