标签:lightoj light oj basic math
1430 - A Question of Time#include <bits/stdc++.h>
using namespace std;
//fun()=3600*(2*h0-hx)+60*(2*m0-13*mx)+2*s0
//13*sx=fun()
//13*sx=fun()+360*120
//13*sx=fun()-360*120
const double eps=1e-10;
const double eps2=1e-3;
int h0,m0,s0;
int t1,t2;
int ans[50];
int len;
double fun(int tmp)
{
double h,m,s;
s=tmp%(13*60)/13.0;
tmp/=13*60;
m=tmp%60;
h=tmp/60;
double ang0=(30*h0)+(m0/2.0)+(s0/120.0);
double ang1=(30*h)+(m/2.0)+(s/120.0);
double ang2=(6*m)+(s/10.0);
return ang1+ang2-2*ang0;
}
int bs(int l,int r,double x)
{
int mid;
while(r-l>1)
{
mid=(l+r)/2;
double cmp=fun(mid)-x;
if(cmp>=eps)
r=mid;
else
l=mid;
}
if(t1<=l&&l<=t2&&fabs(fun(l)-x)<eps2)
return l;
else if(t1<=r&&r<=t2&&fabs(fun(r)-x)<eps2)
return r;
return -1;
}
void solve(int i)
{
int l=i*46800,r=l+46800-1;
int tmp=bs(l,r,0.0);
if(tmp!=-1)
{
ans[len++]=tmp;
}
tmp=bs(l,r,360.0);
if(tmp!=-1)
{
ans[len++]=tmp;
}
tmp=bs(l,r,-360.0);
if(tmp!=-1)
{
ans[len++]=tmp;
}
}
int main()
{
//freopen("in","r",stdin);
//freopen("out","w",stdout);
int t,Case=0;
int h,m,s;
scanf("%d",&t);
while(t--)
{
len=0;
scanf("%d:%d:%d",&h0,&m0,&s0);
scanf("%d:%d:%d",&h,&m,&s);
t1=((h*60+m)*60+s)*13;
scanf("%d:%d:%d",&h,&m,&s);
t2=((h*60+m)*60+s)*13;
for(int i=0; i<12; i++)
{
solve(i);
}
sort(ans,ans+len);
len=unique(ans,ans+len)-ans;
printf("Case %d: %d\n",++Case,len);
int mod;
for(int i=0; i<len; i++)
{
mod=ans[i]%13;
ans[i]/=13;
s=ans[i]%60;
ans[i]/=60;
m=ans[i]%60;
h=ans[i]/60;
printf("%02d:%02d:%02d",h,m,s);
if(mod)
printf(" %d/13",mod);
puts("");
}
}
}
标签:lightoj light oj basic math
原文地址:http://blog.csdn.net/loolu5/article/details/45872489