uva 467 - Synching Signals(暴力+数学)
2014-07-04 10:18
302 查看
题目连接:uva 467 - Synching Signals
题目大意:有n个红绿灯,给出红灯的时间t,那么该灯从0时刻开始就以2*t为周期绿黄红三灯交替,时间分别为t-5,5,t。问所这n个等从第一变为有一个灯不为绿灯开始,要多久才能变成所有的灯刚好都为绿灯。时间超过1小时输出unable to synch after one hour.
解题思路:一小时才3600秒,枚举秒数判断即可。
题目大意:有n个红绿灯,给出红灯的时间t,那么该灯从0时刻开始就以2*t为周期绿黄红三灯交替,时间分别为t-5,5,t。问所这n个等从第一变为有一个灯不为绿灯开始,要多久才能变成所有的灯刚好都为绿灯。时间超过1小时输出unable to synch after one hour.
解题思路:一小时才3600秒,枚举秒数判断即可。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1005; const int maxd = 15; const int INF = 0x3f3f3f3f; char str[maxn]; int n, c[maxd]; inline bool isDight (char ch) { return ch >= '0' && ch <= '9'; } void init () { n = 0; int num = 0, len = strlen(str); for (int i = 0; i <= len; i++) { if (isDight(str[i])) num = num * 10 + str[i] - '0'; else { c[n++] = num; num = 0; } } } bool judge (int u) { for (int i = 0; i < n; i++) { int d = u % (2 * c[i]); if (d >= c[i] - 5) return false; } return true; } int main () { int cas = 1; while (gets(str) != NULL) { init(); int s = INF; for (int i = 0; i < n; i++) s = min(s, c[i]); s -= 5; bool flag = true, t = true; for (int u = s+1; u <= 3600; u++) { if (t) { if (judge(u)) t = true; else t = false; } else { if (judge(u)) { flag = false; printf("Set %d synchs again at %d minute(s) and %d second(s) after all turning green.\n", cas++, u/60, u%60); break; } } } if (flag) printf("Set %d is unable to synch after one hour.\n", cas++); } return 0; }
相关文章推荐
- Joking with Fermat's Last Theorem UVA - 12665 (数学,暴力)
- UVALive 7267(数学暴力)
- uva 10620 - A Flea on a Chessboard(暴力+数学)
- UVa 11461 - Square Numbers【数学,暴力】
- uva 1069 - Always an integer(数学+暴力)
- UVALive 7511 L - Multiplication Table 数学模拟题,暴力
- UVA 12898 And Or 数学暴力
- uva 617- Nonstop Travel(暴力+数学)
- uva 618 - Doing Windows(暴力+数学)
- UVa 269 Counting Patterns 解题报告(暴力)
- uva 11762 数学期望+记忆化搜索
- 【数论】Irrelevant Elements, ACM/ICPC NEERC 2004, UVa1635 【组合数学】
- UVA 11605 - Lights inside a 3d Grid(概率+数学)
- uva580(数学题)
- 【数学期望】Candy, ACM/ICPC Chengdu 2012, UVa1639 【精度】
- UVA 757 Gone Fishing(贪心 + 暴力)
- UVA 10025(数学)
- UVA 11388-GCD LCM(数学)
- Uva 11538 Chess Queen (数学规律题)
- UVALive 6893 The Big Painting(二维hash,暴力)