Probability Through Experiments

题目连接:https://icpcarchive.ecs.baylor.edu/external/61/6142.pdf


Mathematicians have often solved problems by just doing some simulation or experiments. For example, the value of pi (p) can be approximately determined by randomly plotting points in a square that inscribes a circle. Because if the square is a 250x250 square, then its area is 62500 and the area of the inscribed circle is pi*1252=15625pi. As the points are plotted randomly, so it can be assumed that number of points inside the circle and total number points plotted in the square is proportional to their respective area. So, in this way, the value of pi can approximately be determined by counting how many points are inside the circle (Figure 1). The value of pi can even be determined using a more sophisticated experiment like the Buffon’s needle experiment (Figure 2).

 

Sample Input

Sample Output

4 71

234.600

33.576

20.375

84.908

7 7

11.586

114.435

248.411

108.640

287.629

150.224

340.481

0 0

 

Case 1: 2

Case 2: 12





周末做了一次BUAA 的练习,发现这题有点意思。

题目就是求一个元上的点能组成多少个锐角三角行;

给出来各个点的度数,而本题发现与圆的半径没关系,多余的条件,本题主要考虑到锐角三角行,那么我们不妨考虑一下钝角三角形的个数和直角三角形,然后用总数减去钝角三角形和直角,而钝角和直角三角行有个特点,就是每个三角形在同一个半圆内;那么这样就好考虑了,而注意大于360度的情况,而我的处理就是开一个2*n的数组,然后求解就比价容易,而本题用来二分查找和排序等问题:



代码:


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL long long
#define eps 1e-6
double a[50000];

int main() {
    int n,r;
    int t=1;
    while(cin>>n>>r) {
        if(n==0&&r==0) break;

        for(int i=1; i<=n; i++) {
            scanf("%lf",&a[i]);
        }

        LL all=(LL)n*(n-1)*(n-2)/6;

        sort(a+1,a+1+n);

        for(int i=1; i<=n; i++) {
            a[i+n]=a[i]+360.00;
        }

        for(int i=1; i<=n; i++) {
            int l,r,mi;
            l=i;
            r=2*n-1;
            while(l<r) {
                mi=(l+r+1)/2;
                if(a[mi]-a[i]<=180.00+eps) {
                    l=mi;
                } else {
                    r=mi-1;
                }

            }
            l=l-i;
            LL ans=(LL)l*(l-1)/2;
            all-=ans;
    
        }
        cout<<"Case "<<t++<<": ";
        cout<<all<<endl;
    }

    return 0;
}


/*


4 71
234.600
33.576
20.375
84.908
7 7
11.586
114.435
248.411
108.640
287.629
150.224
340.481


*/


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值