UVa 1529 - Clock (模拟)

题意

给出起始时间和终止时间,问这段时间内分针超过了时针几次。

思路

这类问题都要把时间转化成最小单位。

分针一分钟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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值