您的位置:首页 > 其它

CSU 1602 Needle Throwing Game (投针问题)

2015-05-08 21:20 190 查看

1602: Needle Throwing Game

Time Limit: 5 Sec Memory Limit: 128 MB
Submit: 48 Solved: 25
[Submit][Status][Web Board]

Description

There are many parallel lines on the ground with the distance of D between each adjacent two. Now, throwing a needle randomly on the ground,please calculate the possibility of that the needle can be across one of the lines.

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
const double PI=acos(-1.0);
int main()
{
double D,L,P;
while(scanf("%lf %lf",&D,&L)!=EOF)
{
if(L<D) P=2*L/(PI*D);
else P=1+(2.0/PI)*((L*1.0/D)*(1-sqrt((1-(D*D)/(L*L))))-asin(D*1.0/L));
P=P*10000;
printf("%d\n",(int)P);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: