hdoj5387【模拟】

题意:
略;
思路:
把所有的角度按照分母的形式写,中间不要约,不要除。。。(然后我就wa了),本来是想保证结果的正确性,最后会造成约好以后分子很大。。>360°;
/*
这个案例不错,妈的,随手测出来的,(wa的代码)发现分子或者单一的会变成负数。
还是可以的,年轻人,wa那么多发。
21:04:05
*/
贴一发挫code….

#include<cstdio>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define eps 1e-8
typedef __int64 LL;

int make(int n)
{
    while(n>360)//变小;
        n-=360;
    if(n>=180)
        n=360-n;
    return n;
}

int make2(int a,int b)
{
    while(a>360*b)//变小;
        a-=360*b;
    if(a>=b*180)
        a=360*b-a;
    return a;
}

int main()
{
    int t;
    int hh,mm,ss;
    int ah,am,as,bh,bm,bs;
    int x,y,g;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d:%d:%d",&hh,&mm,&ss);
        hh%=24;
        as=ss*6;            bs=1;
        am=ss+60*mm;        bm=10;
        ah=3600*hh+60*mm+ss;bh=120;

        x=abs(ah*bm-am*bh);
        y=bh*bm;
        g=__gcd(x,y);
        x/=g;
        y/=g;
        if(x%y==0)
        {
            x=make(x);
            printf("%d ",x);
        }
        else
        {
            x=make2(x,y);
            printf("%d/%d ",x,y);
        }

        x=abs(ah*bs-as*bh);
        y=bh*bs;
        g=__gcd(x,y);
        x/=g;
        y/=g;
        if(x%y==0)
        {
            x=make(x);
            printf("%d ",x);
        }
        else
        {
            x=make2(x,y);
            printf("%d/%d ",x,y);
        }

        x=abs(am*bs-as*bm);
        y=bm*bs;
        g=__gcd(x,y);
        x/=g;
        y/=g;
        if(x%y==0)
        {
            x=make(x);
            printf("%d ",x);
        }
        else
        {
            x=make2(x,y);
            printf("%d/%d ",x,y);
        }
        puts("");
    }
    return 0;
}
posted @ 2016-08-13 13:16  see_you_later  阅读(110)  评论(0编辑  收藏  举报