Description
There is many parallel lines on the ground with the distance of D between each adjacent. Now, throwing a needle randomly on the ground,please calculate the possibility of this needle can be across one of the Lines.
Input
The input consists of multiple test cases. Each test case contains 2 integers d, l to a single line (1 <= D, l <= 100). The input is ended with EOF.
Output
For each test case, print a 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
Bare needle problem, do not know the child shoes can own Baidu, direct formula ... For this formula problem, know the difference between the formula and the unknown moment is reflected
#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 ((n (d*d)/(L*L)))-asin (d*1.0/l)); p=p*10000; printf ("%d\n", (int) P); } return 0;}
Csu1602:needle throwing Game (pin problem)