题解:UVA1529 时钟

· · 题解

考点:前缀和+数学知识。

思路

数学思维

分针每 60 分钟转一圈,所以每分钟转 360÷60=6°。 时针 12\times60=720 分钟转一圈,每分钟转 360÷720=0.5°。 而每小时内分针想要越过时针就得从 12 的位置出发,一直到时针所在的位置,而时针在这期间也会继续顺时针移动。

所以这就沉了追及问题,追及问题的公式是 路程差\div速度差,而路程差是速度差是 6-05=5.5° ::::success[AC 代码]

#include<bits/stdc++.h>
#define int long long
using namespace std;
double f[1000005];
int a,b,c,d;
signed main(){
    for(int i=1;i<=60;i++){
        f[i]=f[i-1]+720.0/11;
    }
    cout<<"Program 3 by team X \nInitial time Final time Passes \n";
    while(cin>>a>>b>>c>>d){
        int x=a*60+b,y=c*60+d,ans=0;
        if(x>y){
            y+=720;
        }
        for(int i=1;i<=60;i++){
            if(f[i]>=x&&f[i]<=y){
                ans+=1;
            }
        }
        printf("       %02d:%02d       %02d:%02d %7d\n",a,b,c,d,ans);
    }
    cout<<"End of program 3 by team X\n";
    return 0;
}

::::