HDU 5276 YJC tricks time 时针分针视角
HDU 5276 YJC tricks time 时针分针角度
题意:给定一个角度x,问是否存在一个时间点,使得时针分针成 x 度角。题中将 x 扩大了12000倍,且只需要求出10秒的整数倍的时间点。按时间从早到晚输出。没有则不输出。
是很水。。。。。可是比赛的时候不知道怎么脑残了把个角度算错了。大于180度的角angle脑残地转换成了angle - 180我也是醉了。。。。。比赛的时候居然还能通过。。。。。
从 0 时 0 分 0 秒到 11 时 59 分 59 秒,每隔10秒枚举时间点,注意每隔10秒分针角度+1,扩大12000倍后就是12000,同理时针角度+1000,注意加到360*12000的时候要变为0,然后计算角度看是否等于题目所给的角度即可。
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map> #include <set> using namespace std; const int INF = 360*12000; 扩大12000倍后的周角360度 int x; void solve() { int ss = 0; int h = 0, m = 0; for(ss = 0; ss < 43200; ss += 10) { if(m == INF) m = 0; int angle = abs(m - h); if(angle > INF/2) angle = INF - angle; //开始写成了angle -= INF/2好想撞墙 if(angle == x) { if(ss/3600 < 10) //前导0 printf("0"); printf("%d:", ss/3600); if(ss/60%60 < 10) printf("0"); printf("%d:", ss/60%60); if(ss%60 < 10) printf("0"); printf("%d\n", ss%60); } m += 12000; h += 1000; } } int main() { while(scanf("%d", &x) != EOF) solve(); return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。