您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm-icpc