4 00:00:00 06:00:00 12:54:55 04:40:00
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120这是一道简单模拟,但我做了挺长时间,果然模拟题还是很弱啊。。这里注意尽量不要涉及小数,因为会影响精度。#include<iostream> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<string> #include<algorithm> using namespace std; int c[10][4],e,f; int gcd(int a, int b){ return a == 0 ? b : gcd(b % a, a); } void jian(int a,int b,int c,int d){ int i,j,t1,t2,t; t1=a*d-b*c; t2=b*d; t=gcd(t2,t1); e=t1/t; f=t2/t; } int main() { int h,m,t,s,n,i,j,T,x2,y2,x3,y3; char c1,c2; double b1,b2,b3; scanf("%d",&T); while(T--) { scanf("%d:%d:%d",&h,&m,&s); if(h>=12)h-=12; t=h*3600+m*60+s; c[1][1]=t; c[1][2]=120; c[2][1]=m*60+s; c[2][2]=10; c[3][1]=s*6; c[3][2]=1; e=f=0; jian(c[1][1],c[1][2],c[2][1],c[2][2]); if(e*f>0){ e=f=0; jian(c[1][1],c[1][2],c[2][1],c[2][2]); if(e>f*180)jian(360,1,e,f); if(f==1)printf("%d ",e); else printf("%d/%d ",e,f); } else{ e=f=0; jian(c[2][1],c[2][2],c[1][1],c[1][2]); if(e>f*180)jian(360,1,e,f); if(f==1)printf("%d ",e); else printf("%d/%d ",e,f); } e=f=0; jian(c[1][1],c[1][2],c[3][1],c[3][2]); if(e*f>0){ e=f=0; jian(c[1][1],c[1][2],c[3][1],c[3][2]); if(e>f*180)jian(360,1,e,f); if(f==1)printf("%d ",e); else printf("%d/%d ",e,f); } else{ e=f=0; jian(c[3][1],c[3][2],c[1][1],c[1][2]); if(e>f*180)jian(360,1,e,f); if(f==1)printf("%d ",e); else printf("%d/%d ",e,f); } e=f=0; jian(c[2][1],c[2][2],c[3][1],c[3][2]); if(e*f>0){ e=f=0; jian(c[2][1],c[2][2],c[3][1],c[3][2]); if(e>f*180)jian(360,1,e,f); if(f==1)printf("%d ",e); else printf("%d/%d ",e,f); } else{ e=f=0; jian(c[3][1],c[3][2],c[2][1],c[2][2]); if(e>f*180)jian(360,1,e,f); if(f==1)printf("%d ",e); else printf("%d/%d ",e,f); } printf("\n"); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/kirito_acmer/article/details/47622743