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

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

Author

PAN, Minghao

Source

ZJCPC2004

分析:

三个指针走的角速度:

秒针速度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;
}

时间: 2024-11-13 08:47:01

HDU 1006 模拟的相关文章

HDU 4930 模拟

Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 266    Accepted Submission(s): 87 Problem Description Fighting the Landlords is a card game which has been a heat for yea

HDU 1006 Tick and Tick 解不等式解法

一开始思考的时候觉得好难的题目,因为感觉很多情况,不知道从何入手. 想通了就不难了. 可以转化为一个利用速度建立不等式,然后解不等式的问题. 建立速度,路程,时间的模型如下: /*************************************************************************** * * * 秒钟的速度s=6°/s,分针是1/10°/s,时针是1/120°/s * * 所以相对速度s_m=59/10°/s,s_h=719/120°/s,m_h=12

HDU 1006 [Tick Tick]时钟问题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题目大意:钟表有时.分.秒3根指针.当任意两根指针间夹角大于等于n°时,就说他们是happy的,问一天有百分之多少时间是happy的. 关键思想:两根指针两根指针地考虑,从重合到重合中有且仅有一段连续时间这两根指针是happy的.共有3种组合(时分.分秒.时秒),所以若以时间为横轴,夹角为纵轴,图像为三个连续三角形.另y大于等于n,得到的图像求符合区间的长度. 代码如下: //多个连续三角区域

HDU 1006 Tick and Tick(时钟,分钟,秒钟角度问题)

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22203    Accepted Submission(s): 5877 Problem Description The three hands of the

hdu 1022 模拟栈

其实就是模拟一下栈啦. 1 #include <iostream> 2 using namespace std; 3 4 const int N = 10; 5 char o1[N]; 6 char o2[N]; 7 char s[N]; 8 int ans[N * 2]; 9 10 int main () 11 { 12 int n; 13 while ( cin >> n ) 14 { 15 cin >> o1 >> o2; 16 int top = 0

hdu 4054 模拟 练习十六进制输出

http://acm.hdu.edu.cn/showproblem.php?pid=4054 貌似一般区域赛都会有一道水题 这道题PE了一次  因为输出每个数其实是两个位 如果用空格补齐的话  应该用两个空格 我用了一个空格,,, 学到: 1.%x  十六进制输出  可以输出整型,字符型等等 2.%02x  保证两位 而且会输出先导0的两位 //#pragma comment(linker, "/STACK:102400000,102400000") #include <cstd

hdu 5246(模拟)

题解:直接模拟 #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int N = 10005; long long n, m, k; long long s[N]; int main() { int t, cas = 1; scanf("%d", &t); while (t--) { scanf("%lld%l

hdu 5386 模拟

想明白以后会发现其实就是模拟... 因为每次只能给一整行或者一整列赋值,所以目标矩阵一开始一定有一行或者一列上数字都是相同的,然后找到对应的操作,把那一行或者那一列标记为访问过.然后新的矩阵也一定能找到一行或者一列数字都相同,再找到相应的操作,标记那一行或者那一列,依次类推,然后没有用到的操作随便找个顺序就好了.其实初始矩阵并没有什么用...... 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio>

HDU 5071 模拟

考察英语的题 - -# 按条件模拟,一遍就行了,每个聊天对象有其价值U,数组模拟队列过程即可,若存在Top标记,则和Top标记的人聊天,否则和队列的第一个人聊天 mark记录队尾,top记录Top操作,data[i].p记录U,data[i].x记录chat数,data[i].y记录该人是否被删除 Add U:在 队尾插入价值为U的人,需要特判U人已经存在 Close U::在整个队列中查找价值为U的人,将其删除,需要特判该人不存在 Chat x:当前聊天页面的人chat+=x,特判当前队列没有