xmu 1228

#include<iostream>  
#include<cmath>  
#include<time.h>  
using namespace std;  
#define N 1000000  
double Randomf(double a, double b)  
{  
    double c;  
    c = (double)(a+(b-a)*1.0*rand()/RAND_MAX);  
    return c;  
}  
int Randomi(int a, int b)  
{  
    int c;  
    c=(int)Randomf((double)a,(double)b);  
    return c;  
}  
  
int main()  
{  
    int n ;  
    cin>>n;  
    srand((unsigned)time(NULL) );  
    double x[10],y[10],r[10];  
    double a,b;  
    int cnt=0;  
    for(int i=0;i<n;i++)  
    {  
        cin>>x[i]>>y[i]>>r[i];  
    }  
    for(int i=1;i<=N;i++)  
    {  
        a=Randomf(0,1);  
        b=Randomf(0,1);  
        for(int j=0;j<n;j++)  
        {  
            double L=sqrt((a-x[j])*(a-x[j])+(b-y[j])*(b-y[j]));  
            if(L<=r[j])  
            {  
                cnt++;  
                break;  
            }  
        }  
    }  
    printf("%lf\n",(double)cnt*1.0/N);  
    return 0;  
}  

你可能感兴趣的:(c,null,ini)