标签:style blog http color io 2014
#include <stdio.h> #include <string.h> #include <math.h> const double esp = 1e-6; int n, vis[105]; struct D { double l; int g, y, r; void scanf_() { scanf("%lf%d%d%d", &l, &g, &y, &r); } } d[10]; bool judge(int vv) { double v = vv * 1.0 / 3600; for (int i = 0; i < n; i++) { double t = d[i].l / v; int dd = (int)t / (d[i].g + d[i].y + d[i].r); t -= dd * 1.0 * (d[i].g + d[i].y + d[i].r); if (t - 1.0 * (d[i].g + d[i].y) > -esp) return false; } return true; } void print() { int flag = 1, i = 30; for (; i <= 60; i++) { if (vis[i]) { printf("%d", i); flag = 0; break; } } i++; for (; i <= 60; i++) { if (vis[i] && vis[i - 1] == 0) printf(", %d", i); else if (vis[i] && vis[i - 1] && vis[i + 1] == 0) printf("-%d", i); } if (flag) printf("No acceptable speeds."); printf("\n"); } int main() { int cas = 0; while (~scanf("%d", &n) && n != -1) { for (int i = 0; i < n; i++) d[i].scanf_(); memset(vis, 0, sizeof(vis)); for (int i = 30; i <= 60; i++) { if (judge(i)) vis[i] = 1; } printf("Case %d: ", ++cas); print(); } return 0; }
UVA 617 - Nonstop Travel(数论+暴力枚举),码迷,mamicode.com
UVA 617 - Nonstop Travel(数论+暴力枚举)
标签:style blog http color io 2014
原文地址:http://blog.csdn.net/accelerator_/article/details/24634069