HDU 5387 乱搞

点击打开链接

题意:给个时间,然后问时针分针秒针两两的角度

思路:对于每一个来说,都转化成秒,然后分类讨论一下即可,只要能将样例写出来就不会错的

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=100010;
char str[10];
int gcd(int a,int b){
    return b? gcd(b,a%b):a;
}
int main(){
    int T,H,M,S;
    scanf("%d",&T);
    while(T--){
        scanf("%s",str);
        H=(str[0]-'0')*10+(str[1]-'0');
        M=(str[3]-'0')*10+(str[4]-'0');
        S=(str[6]-'0')*10+(str[7]-'0');
        if(H>=12) H-=12;
        int ans1,ans2,ans3,hhh,mmm,aaa;
        hhh=M*60+S+H*60*60;
        mmm=12*(M*60+S);
        aaa=abs(hhh-mmm);
        aaa=min(43200-aaa,aaa);
        aaa*=360;
        if(aaa==0) printf("0 ");
        else{
            int kkk=gcd(aaa,43200);
            if(kkk==43200) printf("%d ",aaa/kkk);
            else printf("%d/%d ",aaa/kkk,43200/kkk);
        }
        hhh=M*60+S+H*60*60;
        mmm=12*60*S;
        aaa=abs(hhh-mmm);
        aaa=min(43200-aaa,aaa);
        aaa*=360;
        if(aaa==0) printf("0 ");
        else{
            int kkk=gcd(aaa,43200);
            if(kkk==43200) printf("%d ",aaa/kkk);
            else printf("%d/%d ",aaa/kkk,43200/kkk);
        }
        hhh=M*60+S;
        mmm=60*S;
        aaa=abs(hhh-mmm);
        aaa=min(3600-aaa,aaa);
        aaa*=360;
        if(aaa==0) printf("0 ");
        else{
            int kkk=gcd(aaa,3600);
            if(kkk==3600) printf("%d ",aaa/kkk);
            else printf("%d/%d ",aaa/kkk,3600/kkk);
        }
        printf("\n");
    }
    return 0;
}

你可能感兴趣的:(ACM,HDU)