注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Minary_Acdream

http://f10.moe/

 
 
 

日志

 
 

[hdu]1006 Tick and Tick  

2012-07-31 12:45:03|  分类: HDU |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
这题需注意的有两点。这是钟并不是一秒一秒走的,它是连续的走的。也就是存在0.000001s的可能性。
在这种情况下离散化就不能去做了;
还有一点就是卡精度。
先放题目:

Tick and Tick

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5184    Accepted Submission(s): 1396


Problem Description
The three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of this and each of them would like to stay away from the other two. A hand is happy if it is at least D degrees from any of the rest. You are to calculate how much time in a day that all the hands are happy.
 

Input
The input contains many test cases. Each of them has a single line with a real number D between 0 and 120, inclusively. The input is terminated with a D of -1.
 

Output
For each D, print in a single line the percentage of time in a day that all of the hands are happy, accurate up to 3 decimal places.
 

Sample Input
0 120 90 -1
 

Sample Output
100.000 0.000 6.251
 

Author
PAN, Minghao
 

Source
 

Recommend
JGShining

下面是我的错误代码:



#include<iostream>
#include<cmath>
using namespace std;

int
main()
{

int
N;
freopen("bata.out","w",stdout);
while
(cin>>N)
{

if
(N == -1) break;
double
count = 0;
double
angles[86401],anglem[86401],angleh[86401];
for
(int i = 0;i < 86400;i ++)
{

angles[i] = (i * 6) % 360;
anglem[i] = i % 360 * 0.1;
angleh[i] = 1.0 / 240 * i;
printf("%.2lf %.2lf %.2lf\n",angles[i],anglem[i],angleh[i]);
}

for
(int i = 0;i < 86400;i ++)
{

double
a,b,c;
a = abs(angleh[i] - anglem[i]);
b = abs(anglem[i] - angles[i]);
c = abs(angles[i] - angleh[i]);
if
(abs(a > 180)) a = abs(a - 360);
if
(abs(b > 180)) b = abs(b - 360);
if
(abs(c > 180)) c = abs(c - 360);
if
(a >= N && b >= N && c >= N)//&& a <= 180 && b <= 180 && c <= 180
count ++;
}

cout<<count<<endl;
printf("%.3lf\n",count/864);
}

}

/*
0<=D<=120
Sample Input
0
120
90
-1


Sample Output
100.000
0.000
6.251
*/



最后=。 - 实在倒腾不出来,弱菜无奈。。就先帖着某牛的代码了。希望对你们有点帮助:



#include<iostream>
#include<iomanip>
using namespace std;
//给跪了...ORZ
//const double w_h=1.0/120,w_m=1./10,w_s=6.0; //角速度
const double hm=11.0/120,hs=719.0/120,sm=59.0/10; //相对角速度
// 将相对角速度变成周期。(即两针间须要多久呈现夹角的轮回)
// 同样可求得三个周期的最小公倍数为 43200 秒,即12小时,呵呵,料想之中啊。
const double T_hm=43200.0/11,T_hs=43200.0/719,T_sm=3600.0/59; //相对周期

inline
double min(double a,double b,double c)
{

double
temp=(a>b)?b:a;

return
(c>temp)?temp:c;
}


inline
double max(double a,double b,double c)
{

double
temp=(a>b)?a:b;

return
(c>temp)?c:temp;
}


int
main()
{

double
degree;
double
x[3],y[3];
double
m[3],n[3];
double
end,begin,sum;

while
(cin>>degree , degree!=-1)
{

// 策画第一次满足前提的时候
x[0]=degree/hm;
x[1]=degree/hs;
x[2]=degree/sm;
// 策画第一次不满足前提的时候
y[0]=(360-degree)/hm;
y[1]=(360-degree)/hs;
y[2]=(360-degree)/sm;

sum=0.0;
// 三重轮回找出所有的时候总和,当然这三重轮回的次序是可以打乱的
for(m[0]=x[0],n[0]=y[0];n[0]<=43200.000001;m[0]+=T_hm,n[0]+=T_hm)
{

for
(m[1]=x[1],n[1]=y[1];n[1]<=43200.000001;m[1]+=T_hs,n[1]+=T_hs)
{

if
(n[0]<m[1])
break
;
if
(m[0]>n[1]) // 这是为了提前断定是否有交集
continue;

for
(m[2]=x[2],n[2]=y[2];n[2]<=43200.000001;m[2]+=T_sm,n[2]+=T_sm)
{

if
(n[0]<m[2] || n[1]<m[2])
break
;
if
(m[0]>n[2] || m[1]>n[2])
continue
;

begin=max(m[0],m[1],m[2]);// 取它们的交集
end=min(n[0],n[1],n[2]);

if
(end>begin)
sum+=end-begin;
}
}
}


cout<<setiosflags(ios::fixed)<<setprecision(3)<<sum*100.0/43200<<endl;
}


return
0;
}




  评论这张
 
阅读(1489)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018