您的位置:首页 > 其它

"巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场(重现) HDU 5705

2016-05-28 22:03 387 查看

Clock

[b]Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

Total Submission(s): 8    Accepted Submission(s): 6
[/b]

[align=left]Problem Description[/align]
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).

 

[align=left]Input[/align]
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).

 

[align=left]Output[/align]
For each test case, output a single line contains test case number and the answer HH:MM:SS.

 

[align=left]Sample Input[/align]

0:59:59
30
01:00:00
30

 

[align=left]Sample Output[/align]

Case #1: 01:00:00
Case #2: 01:10:54

 

[align=left]Source[/align]
"巴卡斯杯"
中国大学生程序设计竞赛 - 女生专场
 

[align=left]Recommend[/align]
liuyiding   |   We have carefully selected several similar problems for you:  5711 5710 5709 5708 5700 
 

告诉你现在的时间,叫你找出一个时间让时针分针所成角度为题目给定的。
设x为分。
我们假设一圈度数为360*120 则时针一小时走3600度。分针一分钟走720度。
设当前时间为h,x分 则时针的角度为h*3600+x*60.分针的角度为720*x;
所以x=(3600*h-120*angle)/660 或者x=(3600*h+120*angle)/660   角度已知,所以秒为%660/11 枚举小时即可求解。
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
//void printf(int begin,int end,int mid)
//{
// int i;
// if(begin>end)
// return;
// for(i=begin; i<=end; i++)
// if(b[i]==a[mid])
// break;
// printf(begin,i-1,mid+1); //中序,先左,后跟,再右。此时i为跟节点,左子树必定在begin到i-1里面。
// printf(i+1,end,mid-begin+i+1);//中序,先左,后跟,再右。此时i为跟节点,右子树必定在i+1到end里面。
// cout<<a[mid];
// if(mid==1)
// cout<<endl;
// else
// cout<<" ";
//}
//struct node
//{
// int id;
// char s[1000];
//};
//bool cmp(node a,node b)
//{
// return a.id>b.id;
//}
//char s[1005][1005];
//int dir[4][2]= {1,0,-1,0,0,1,0,-1};
//char g[5]= {"girl"};
//char c[5]= {"cat"};
//int n,m;
//int dfs1(int x,int y,int cnt)
//{
// int i;
// if(x<0 ||y<0 ||x>=n ||y>=m)
// return 0;
// if(s[x][y]!=g[cnt])
// return 0;
// if(cnt==3)
// return 1;
// int res=0;
// for(i=0; i<4; i++)
// {
// int dx=x+dir[i][0];
// int dy=y+dir[i][1];
// res+=dfs1(dx,dy,cnt+1);
// }
// return res;
//}
//int dfs2(int x,int y,int cnt)
//{
// int i;
// if(x<0 ||y<0 ||x>=n ||y>=m)
// return 0;
// if(s[x][y]!=c[cnt])
// return 0;
// if(cnt==2)
// return 1;
// int res=0;
// for(i=0; i<4; i++)
// {
// int dx=x+dir[i][0];
// int dy=y+dir[i][1];
// res+=dfs2(dx,dy,cnt+1);
// }
// return res;
//}
void update()
{

}
int main()
{
int h,f,m;
int icase=0;
while(~scanf("%d:%d:%d",&h,&f,&m))
{
int ang;
cin>>ang;
ang*=120;
int t1=3600*h+60*f+m;
int a1,a2,a3;
int inff=1e8;
for(int i=0; i<12; i++)
{
int h1=3600*i-ang;
int fen1=h1/660;
int miao1=h1%660/11;
int t2=i*3600+fen1*60+miao1;
int T=t2-t1;
if(T<=0)T+=60*60*12;
if(T<inff)
{
a1=i;
a2=fen1;
a3=miao1;
inff=T;
}
h1=3600*i+ang;
fen1=h1/660;
miao1=h1%660/11;
t2=i*3600+fen1*60+miao1;
T=t2-t1;
if(T<=0)T+=60*60*12;
if(T<inff)
{
a1=i;
a2=fen1;
a3=miao1;
inff=T;
}
}
printf("Case #%d: %02d:%02d:%02d\n",++icase,a1,a2,a3);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM算法