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
  • 相关阅读:
    Linux:目录结构
    Linux安装日志(anaconda-ks.cfg、install.log、install.log.syslog)
    Docker:Dockerfile基础知识
    Docker:容器数据卷
    多线程设计模式:两阶段终止模式
    多线程:Thread中的常见方法
    多线程:查看进程线程方法
    多线程:创建线程
    Apollo:工作原理 核心概念
    Apollo:环境搭建
  • 原文地址:https://www.cnblogs.com/clliff/p/4488889.html
Copyright © 2011-2022 走看看