zoukankan      html  css  js  c++  java
  • CSU 1602 Needle Throwing Game (投针问题)

    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.

    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 2
    2 4

    Sample Output

    3183
    8372

    HINT

     

    Source

    题意:给定平行线的间距和针的长度,求随机投放针,针与平行线相交的概率是多少。

    分析:投针问题,公式题。

    当L<D时.公式为:P=2L/Dπ

    当L>=D时,P=1-(1/π)[2arcsin(D/L)-(2L/D)+(2/D)sqrt(L^2-D^2)]

    #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
    ",(int)P);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    P20 HTTP 方法的安全性与幂等性
    P19 查询参数
    P18 写代码:过滤和搜索
    P17 过滤和搜索
    P16 HTTP HEAD
    golang的json操作[转]
    Android中的Service 与 Thread 的区别[转]
    iOS的block内存管理
    Go并发编程基础(译)
    golang闭包里的坑
  • 原文地址:https://www.cnblogs.com/clliff/p/4488889.html
Copyright © 2011-2022 走看看