CSU1602: Needle Throwing Game(投针问题)
来源:互联网 发布:vb打印输出九九乘法表 编辑:程序博客网 时间:2024/04/28 19:50
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.
Input
The input consists of multiple test cases. Each test case contains 2 integers D, L on a single line (1 <= D, L <= 100). The input is ended with EOF.
Output
For each test case, print an integer of (int)(P*10000) where P is the possibility asked above. For example, when P = 0.25658,you should output 2565.
Sample Input
4 22 4
Sample Output
31838372
HINT
Source
裸的投针问题,不知道的童鞋可以自己百度,直接公式。。。
对于这种公式题,知道公式与不知道的差别瞬间就体现出来了
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <algorithm>using namespace std;#define ls 2*i#define rs 2*i+1#define up(i,x,y) for(i=x;i<=y;i++)#define down(i,x,y) for(i=x;i>=y;i--)#define mem(a,x) memset(a,x,sizeof(a))#define w(a) while(a)#define LL long longconst double PI = acos(-1.0);#define Len 200005#define mod 19999997const int INF = 0x3f3f3f3f;#define exp 1e-8int main(){ double L,D; double P; w(~scanf("%lf%lf",&D,&L)) { 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;}
1 0
- CSU1602: Needle Throwing Game(投针问题)
- POJ 2598 Match Throwing Game 笔记
- TextView.setText() throwing NullPointerException问题
- Buffon's Needle An Analysis and Simulation------蒙特卡洛法模拟蒲丰(Buffon)投针实验-使用Matlab
- spring aop中的After throwing增强问题
- UVa 10940 Throwing cards away II (约瑟夫问题)
- *haystack++ != *needle++
- needle常见命令参考
- Dice Throwing
- Ruby中的IoC容器:needle
- [ANN] Needle 1.2.0发布
- Ruby中的IoC容器:needle
- needle之 Quick Start Guide
- Jump Game 问题
- Game设计中的一些问题
- GDUFS1146 Banana Game 博弈问题
- Jump Game 跳台阶问题
- Nim Game问题及解法
- laravel provider 配置 not find 问题解决
- 【leetcode】Populating Next Right Pointers in Each Node II
- https://leetcode.com/problems/container-with-most-water/
- unix平均负载average load计算方法
- ACM-抽签(二分搜索)
- CSU1602: Needle Throwing Game(投针问题)
- hdu 3264 Open-air shopping malls 计算几何 相交圆的面积 二分
- 一起talk Vim吧(第三回:Vim刀法之移动光标)
- 浅谈java类加载机制
- HDU ACM 3308 LCIS->最长连续递增子序列->线段树+区间合并+单点修改
- HibernateUtil类(工具类的基本操作)
- UVA - 11127 Triple-Free Binary Strings dfs
- mybatis+spring
- 高效程序员的45个习惯之敏捷,高效软件开发之道