HDU-Tick and Tick

本文介绍了一种计算时钟的时针、分针、秒针在一天中同时保持至少D度角分离的时间百分比的方法。通过设定相对角速度,利用枚举策略找到满足条件的时段交集,最终计算出所有手都“幸福”的总时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.youkuaiyun.com/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 - 6609 的题目解析 由于当前未提供具体关于 HDU - 6609 题目的详细描述,以下是基于一般算法竞赛题型可能涉及的内容进行推测和解答。 #### 可能的题目背景 假设该题目属于动态规划类问题(类似于多重背包问题),其核心在于优化资源分配或路径选择。此类问题通常会给出一组物品及其属性(如重量、价值等)以及约束条件(如容量限制)。目标是最优地选取某些物品使得满足特定的目标函数[^2]。 #### 动态转移方程设计 如果此题确实是一个变种的背包问题,则可以采用如下状态定义方法: 设 `dp[i][j]` 表示前 i 种物品,在某种条件下达到 j 值时的最大收益或者最小代价。对于每一种新加入考虑范围内的物体 k ,更新规则可能是这样的形式: ```python for i in range(n): for s in range(V, w[k]-1, -1): dp[s] = max(dp[s], dp[s-w[k]] + v[k]) ``` 这里需要注意边界情况处理以及初始化设置合理值来保证计算准确性。 另外还有一种可能性就是它涉及到组合数学方面知识或者是图论最短路等相关知识点。如果是后者的话那么就需要构建相应的邻接表表示图形结构并通过Dijkstra/Bellman-Ford/Floyd-Warshall等经典算法求解两点间距离等问题了[^4]。 最后按照输出格式要求打印结果字符串"Case #X: Y"[^3]。 #### 示例代码片段 下面展示了一个简单的伪代码框架用于解决上述提到类型的DP问题: ```python def solve(): t=int(input()) res=[] cas=1 while(t>0): n,k=list(map(int,input().split())) # Initialize your data structures here ans=find_min_unhappiness() # Implement function find_min_unhappiness() res.append(f'Case #{cas}: {round(ans)}') cas+=1 t-=1 print("\n".join(res)) solve() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

black-hole6

你的鼓励将是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值