题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5705

题目:

Problem Description
Given a time HH:MM:SS and one parameter a , you need to calculate next time satisfying following conditions:
1. The angle formed by the hour hand and the minute hand is a
2. The time may not be a integer(e.g. 12:34:56.78), rounded down(the previous example 12:34:56).
Input
The input contains multiple test cases.
Each test case contains two lines.
The first line is the time HH:MM:SS(0≤HH<12,0≤MM<60,0≤SS<60)
The second line contains one integer a(0≤a≤180)
Output
For each test case, output a single line contains test case number and the answer HH:MM:SS.
Sample Input
0:59:59
30
01:00:00
30
Sample Output
Case #1: 01:00:00
Case #2: 01:10:54

题意:给出时间 HH:MM:SS 角度a 问下一个H和M的角度为a的时刻?

思路:

时针每小时30度,每分钟30/60度,每秒1/120 (3600,60,1)
分针每小时360,每分钟6度,每秒6/60,1/10度; (,720,12)避免精度问题全部乘以120 
算出h,m初始角度 h,m之间角度为deg=abs(h-m),暴力枚举几秒后deg==a即可,O(T)

参考:http://www.bubuko.com/infodetail-2051662.html

代码:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
const double eps=1e-;
const int N=2e5+;
int a;
int main()
{
int cas=;
int h,m,s;
while(~scanf("%d:%d:%d",&h,&m,&s))
{
cin>>a;
a*=;
int sum=h*+m*+s;//总的时间(秒)
//h,m初始角度
int hh=sum%(*);
int mm=(sum*)%(*); int ans=;//暴力枚举几秒后
while(true)
{
hh=(hh+)%(*);//时针每秒1/120度,但由于乘了120,所以每次+1度
mm=(mm+)%(*);//分针每秒1/10度,但由于乘了120,所以分针1秒离散成12度
ans++;
int deg=abs(hh-mm);//h,m角度
if(abs(deg-a)<=)//误差在1度内
break;
}
int anss=(ans+s)%;
int ansm=((ans+s)/+m)%;
int ansh=(((ans+s)/+m)/+h)%;
printf("Case #%d: %02d:%02d:%02d\n",cas++,ansh,ansm,anss);
}
return ;
}

hdu5705的更多相关文章

  1. HDU-5705

    Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Problem De ...

  2. 2016女生专场 ABCDEF题解 其他待补...

    GHIJ待补... A.HUD5702:Solving Order Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3276 ...

随机推荐

  1. A.01.10—模块的输出—PWM高端输出

    PWM高端输出比低端输出用得多,如上次提到的卤素灯的控制均是采用高端输出的. PWM高端输出与PWM低端输出的差异就像固态高端输出与固态低端输出的差异类似,从线路失效后对用户的影响来看:高端输出为控制 ...

  2. php+mysql+nginx+liunx 服务搭建

    安装php7相应的yum源   CentOS 7.x:   # rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7 ...

  3. MQ在高并发环境下,如果队列满了,如何防止消息丢失?

    1.为什么MQ能解决高并发环境下的消息堆积问题? MQ消息如果堆积,消费者不会立马消费所有的消息,不具有实时性,所以可以解决高并发的问题. 性能比较好的消息中间件:Kafka.RabbitMQ,Roc ...

  4. [拓展Bsgs] Clever - Y

    题目链接 Clever - Y 题意 有同余方程 \(X^Y \equiv K\ (mod\ Z)\),给定\(X\),\(Z\),\(K\),求\(Y\). 解法 如题,是拓展 \(Bsgs\) 板 ...

  5. Pandas系列(十六)- 你需要学会的骚操作

    pandas有一种功能非常强大的方法,它就是accessor,可以将它理解为一种属性接口,通过它可以获得额外的方法.其实这样说还是很笼统,下面我们通过代码和实例来理解一下. pd.Series._ac ...

  6. java代码调用第三方接口

    一.利用httpclient来字符串参数(url是第三方接口,不带参数,如:http://192.168.16.200:8081/faceInfo/list,param是url后面所要带的参数) pu ...

  7. Mysql漏洞修复方法思路及注意事项

    [系统环境] 系统环境:Red Hat Enterprise Linux Server release 5.4 (Tikanga)  +  5.7.16 MySQL Community Server  ...

  8. express + restful

    express http://www.expressjs.com.cn/ Express 是一个基于 Node.js 平台的极简.灵活的 web 应用开发框架,它提供一系列强大的特性,帮助你创建各种 ...

  9. Linux常用命令大全(非常全!!!)

    Linux常用命令大全(非常全!!!) 最近都在和Linux打交道,感觉还不错.我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因,比较短 ...

  10. MyEclipse编码方式设置

    1.windows -> Preferences -> general -> Workspace: