【HDOJ】1006 Tick and Tick
【题目】 http://acm.hdu.edu.cn/showproblem.php?pid=1006
【报告】
感谢学校的张博文学长给我大致讲解了这道题的做法。以及感谢度娘让我找到了一个不错的解法(http://hi.baidu.com/guoxiangke2008/blog/item/72c59bd5e51841cc51da4bd4.html)。
以下是聊天记录:
计科09-张博文(810311398) 11:31:05
hdu 1006么?
@计科12-施尔宁
计科09-张博文(810311398) 11:31:49
因为每个指针的角速度恒定
所以每个指针的相对角速度恒定
计科09-张博文(810311398) 11:32:52
所以函数图象应该是
这样的三角形的重复
在d和360-d中间的即为所求区域
计科09-张博文(810311398) 11:34:06
题目说三个指针两两happy
所以就是三个这样的图象的公共区间
代码如下:
#include <cstdio>
#include <algorithm>
using namespace std;
const double UB=43200;
const double hm=11.0/120,hs=719.0/120,sm=59.0/10;
const double T_hm=UB/11,T_hs=UB/719,T_sm=3600.0/59;
int main()
{
double d;
double s[3],e[3],ts[3],te[3];
while(scanf("%lf",&d),d!=-1)
{
s[0]=d/hm;
s[1]=d/hs;
s[2]=d/sm;
e[0]=(360-d)/hm;
e[1]=(360-d)/hs;
e[2]=(360-d)/sm;
double sum=0;
for(ts[0]=s[0],te[0]=e[0];ts[0]<UB;ts[0]+=T_hm,te[0]+=T_hm)
{
if(te[0]>UB) te[0]=UB;
for(ts[1]=s[1],te[1]=e[1];ts[1]<UB;ts[1]+=T_hs,te[1]+=T_hs)
{
if(ts[1]>te[0])
break;
if(te[1]<ts[0])
continue;
if(te[1]>UB) te[1]=UB;
for(ts[2]=s[2],te[2]=e[2];ts[2]<UB;ts[2]+=T_sm,te[2]+=T_sm)
{
if(ts[2]>te[1]||ts[2]>te[0])
break;
if(te[1]<ts[0]||te[1]<ts[1])
continue;
if(te[2]>UB) te[2]=UB;
double start=max(max(ts[0],ts[1]),ts[2]);
double end=min(min(te[0],te[1]),te[2]);
if(end>start)sum+=end-start;
}
}
}
printf("%.3f\n",sum*100.0/UB);
}
return 0;
}
别的我不说了,这两个自己选一个玩吧
【程序】
// TASK: Tick and Tick
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
inline double min(double a,double b)
{
return (a<b)?a:b;
}
inline double max(double a,double b)
{
return (a>b)?a:b;
}
class extent
{
public:
double a,b;
extent ()
{
a=b=0;
}
extent (double A,double B)
{
a=A,b=B;
if (a>b) a=b=0;
}
void print ()
{
cout << a
<< " "
<< b <<
endl;
}
double length()
{

浙公网安备 33010602011771号