hdu 5387 Clock 简单数学

来源:互联网 发布:windows平板游戏 编辑:程序博客网 时间:2024/05/22 00:11
#include<stdio.h>#include<string.h>#include<math.h>#include<queue>#include<vector>#include<iostream>#include<string>#include<set>#include<map>#include<algorithm>using namespace std;#pragma comment(linker, "/STACK:1024000000,1024000000")#define nn 1000010#define LL long long#define ULL unsiged long long//#define mod 0x7fffffff#define mod 1100010#define inf oxfffffffffff#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1//        ((`'-"` `""-'`))//         ) -  -  (//        /  (o _ o)  \//        \  ( 0 )  ///       _'-.._ '=' _..-'_//      /`;#'#'#. -. #'#'#;`\//      \_))   '#'   ((_///      #.  ☆ ☆ ☆  .#//      '#.  求 AC!  .#'//       /'#.     .#'\//       _\\'#.   .#'//_//       (((___)'#'(___)))struct node{    LL x,y;};LL gcd(LL a,LL b){    if(b==0) return a;    else return gcd(b,a%b);}node gettime(node a,node b){    node c;    c.x=a.x*b.x;    c.y=abs(a.y*b.x-b.y*a.x);    LL k=gcd(c.x,c.y);    c.x/=k;    c.y/=k;    if(c.y>c.x*180)        c.y=c.x*360-c.y;    return c;}int main(){    int t;    node vs,vm,vh;    vs.y=6,vs.x=1;    vm.y=1,vm.x=10;    vh.y=1,vh.x=120;    scanf("%d",&t);    while(t--)    {        LL h,m,s;        scanf("%lld:%lld:%lld",&h,&m,&s);        LL time=s+m*60+h*60*60;        node ks,kh,km;        ks.y=vs.y*time,ks.x=1;        km.y=vm.y*time,km.x=10;        kh.y=vh.y*time,kh.x=120;        while(ks.y>=ks.x*360)            ks.y-=ks.x*360;        while(km.y>=km.x*360)            km.y-=km.x*360;        while(kh.y>=kh.x*360)            kh.y-=kh.x*360;        node ans1=gettime(kh,km);        node ans2=gettime(kh,ks);        node ans3=gettime(km,ks);        if(ans1.y==0) printf("0 ");        else if(ans1.x==1)            printf("%lld ",ans1.y);        else printf("%lld/%lld ",ans1.y,ans1.x);        if(ans2.y==0) printf("0 ");        else if(ans2.x==1)            printf("%lld ",ans2.y);        else printf("%lld/%lld ",ans2.y,ans2.x);        if(ans3.y==0) printf("0 \n");        else if(ans3.x==1)            printf("%lld \n",ans3.y);        else printf("%lld/%lld \n",ans3.y,ans3.x);    }    return 0;}
计算出角速度,用角速度来计算。
0 0
原创粉丝点击