hdu-Tick and Tick

本文针对HDU在线评测平台上的TickandTick问题,详细解析了如何通过计算时钟三针之间的角度来确定“快乐”状态的时间百分比。文章提供了具体的数学模型和C语言实现代码。

hdu-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
0 120 90 -1
 

Sample Output
100.000 0.000 6.251
 

题目大意

输入一个非负整数D,当时针、分针、秒针,之中任意两者之间的夹角大于D,则会happy。现在要求总的happy的时间占的百分比(基于12个小时),保留三位小数。



解题思路

1、每秒钟的移动速度(多少度),(s:秒针,m:分针,h:时针):   s=6 /s           m=(1/10) /s           h=(1/120) /s

2、三种针之间相对速度 :      s_m=(59/10) /s           s_h=(719/120) /s            m_h=(11/120) /s

3、移动一度所需要的时间:   s_m=(10/59) s            s_h=(120/719) s             m_h=(120/11) s

4、周期:       ts_m=(3600/59) s                 ts_h=(43200/719) s                tm_h=(43200/11) s

所以,假设输入的D=n;则有:

                                                n*s_m + k1*ts_m < T < ts_m - n*s_m + k1*ts_m

                                                n *s_h + k2*ts_h < T < ts_h - n*s_h + k2*ts_h

                                                n* m_h + k3*tm_h <T < tm_h - n*m_h +k3*tm_h

当T同时满足这三个式子时,便是happy的时间;


#include<stdio.h>
#include<math.h>
int main()
{
    int t;
    double n,sm,sh,mh,tsm,tsh,tmh,fsm,fsh,fmh,esm,esh,emh,b1,e1,b2,e2,b3,e3,min,max,sum;
    sm=10.0/59.0;
    sh=120.0/719.0;
    mh=120.0/11.0;
    tsm=3600.0/59.0;
    tsh=43200.0/719.0;
    tmh=43200.0/11.0;
    while(~scanf("%lf",&n))
    {
        if(n<0)break;
        sum=0;
        fsm=n*sm;esm=tsm-fsm;
        fsh=n*sh;esh=tsh-fsh;
        fmh=n*mh;emh=tmh-fmh;
        for(b3=fmh,e3=emh;e3<=43200;b3+=tmh,e3+=tmh)//找出满足三个式子的T,并且求和得到sum
        {
            for(b2=fsh,e2=esh;e2<=43200;b2+=tsh,e2+=tsh)
            {
                if(e2<b3)
                    continue;
                if(b2>e3)
                    break;
                for(t=0,b1=fsm,e1=esm;e1<=43200;t=t+1,b1=fsm+t*tsm,e1=esm+t*tsm)
                {
                    if(e1<b2||e1<b3)
                        continue;
                    if(b1>e2||b1>e3)
                        break;
                    max=b1>b2?b1:b2;
                    max=max>b3?max:b3;
                    min=e1<e2?e1:e2;
                    min=min<e3?min:e3;
                    sum+=min-max;
                }
            }
        }
        printf("%.3lf\n",sum/432.0);//因为要求百分比,所以sum应该除以12个小时即43200秒,再乘以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
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值