UVa 1529 - Clock (模拟)
2015-05-14 11:23
381 查看
题意
给出起始时间和终止时间,问这段时间内分针超过了时针几次。思路
这类问题都要把时间转化成最小单位。分针一分钟6度,时针1分钟0.5度。
因为最多43200秒,所以可以每一秒计算一次各自的角度。这样就可以计算超过几次了。
能够成为超过的条件:
1. 之前分针的角度比时针小过
2. 现在分针的角度比时针大
这样就能算作一次超越。
代码
#include <stack> #include <cstdio> #include <list> #include <cassert> #include <set> #include <fstream> #include <iostream> #include <string> #include <vector> #include <queue> #include <functional> #include <cstring> #include <algorithm> #include <cctype> //#pragma comment(linker, "/STACK:102400000,102400000") #include <string> #include <map> #include <cmath> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/hash_policy.hpp> using namespace std; using namespace __gnu_pbds; #define LL long long #define ULL unsigned long long #define SZ(x) (int)x.size() #define Lowbit(x) ((x) & (-x)) #define MP(a, b) make_pair(a, b) #define MS(arr, num) memset(arr, num, sizeof(arr)) #define PB push_back #define X first #define Y second #define ROP freopen("input.txt", "r", stdin); #define MID(a, b) (a + ((b - a) >> 1)) #define LC rt << 1, l, mid #define RC rt << 1|1, mid + 1, r #define LRT rt << 1 #define RRT rt << 1|1 #define FOR(i, a, b) for (int i=(a); (i) < (b); (i)++) #define FOOR(i, a, b) for (int i = (a); (i)<=(b); (i)++) const double PI = acos(-1.0); const int INF = 0x3f3f3f3f; const double eps = 1e-8; const int MAXN = 2e4+10; const int MOD = 1e9; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; const int seed = 131; int cases = 0; typedef pair<int, int> pii; int main() { //ROP; int h1, m1, h2, m2; puts("Program 3 by team X"); puts("Initial time Final time Passes"); while (~scanf("%d%d%d%d", &h1, &m1, &h2, &m2)) { int s1 = h1*60 + m1, s2 = h2*60 + m2; if (s2 < s1) s2 += 720; bool small = false; int ans = 0; FOOR(i, s1, s2) { int curMin = i % 60; double hour_angle = i*1.0 / 2, min_angle = curMin*6; while (hour_angle > 360) hour_angle -= 360; if (min_angle > hour_angle) { if (small) { ans++; small = false; } } if (min_angle < hour_angle) small = true; } //puts("12345678901234567890123456789012"); FOR(i, 0, 7) putchar(' '); printf("%02d:%02d", h1, m1); FOR(i, 0, 7) putchar(' '); printf("%02d:%02d", h2, m2); printf("%8d\n", ans); } puts("End of program 3 by team X"); return 0; }
相关文章推荐
- uva 1529 - Clock(数论)
- UVA 1529 - Clock(数论)
- UVALive 5880 Vigenère Cipher Encryption (模拟)
- HDU 5387 Clock // 模拟
- UVA 1594:Ducci Sequence (模拟 Grade E)
- hdu5387 六校 Clock(水题 模拟)
- UVa- 227 - Puzzle:单纯模拟 & 数据(字符数组)读入练习
- UVALive 4723 水模拟
- UVa379 - Hi-Q(模拟)
- 2018.2.28【 UVa - 227 】解题报告(紫书练习题,模拟,输出格式)
- UVALive 4097 Yungom (思路--set||优先队列的模拟)
- UVA - 489 Hangman Judge :模拟···WA了N次
- UVA - 177 Paper Folding(规律 + 模拟)
- UVA 156 Ananagrams 模拟+字符串处理
- UVA 10142 Australian Voting(模拟)
- UVALive 6093 Emergency Room --优先队列实现的模拟
- The Same Game UVA 758/Uvalive 5423 大模拟 求最大联通块并清除
- uva 201 Squares 【模拟,处理带坐标的图】
- UVA 1589 Xiangqi(仔细的模拟)
- UVa 489 Hangman Judge (模拟&字符串匹配)