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
  • 相关阅读:
    Oracle EXTRACT()函数与to_char() 函数
    Java内部类
    SQL 之 Group By
    Android LayoutInflater布局填充器
    JS 图片转Base64
    C# 事件与委托的区别
    AngularJS的循环输出
    jquery实现button倒计时
    重新理解B/S和C/S的区别
    HashMap与HashTable
  • 原文地址:https://www.cnblogs.com/clliff/p/4488889.html
Copyright © 2011-2022 走看看