uva_12535 - Probability Through Experiments

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=3980&mosmsg=Submission+received+with+ID+13299007

题解:看这篇博文:http://blog.csdn.net/tri_integral/article/details/9772243

 

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
#include<queue>
#include<utility>

#define MAXN 360050
#define eps 1e-8
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,t) for(int i=s; i<=t; i++)
#define show(x) { cerr<<">>>"<<#x<<" = "<<x<<endl; }
#define showtwo(x,y) { cerr<<">>>"<<#x<<"="<<x<<"  "<<#y<<" = "<<y<<endl; }
using namespace std;

int n,r;
double x[MAXN];

int dcmp(double x)
{
    if(fabs(x) < eps) return 0;
    else              return x < 0 ? -1 : 1;
}

int main()
{
    //freopen("E:\\acm\\input.txt","r",stdin);
    int test_count = 1;
    while(cin>>n>>r)
    {
        if(n==0 && r==0) break;
        REP(i,n) cin>>x[i];
        sort(x,x+n);
        x[n] = 360;

        long long ans = (long long)n*(n-1)*(n-2)/6;
        REP(i,n)
        {
            long long dis;
            if(dcmp(x[i]-180) < 0)
                dis = upper_bound(x,x+n,x[i]+180+eps)- x - i - 1;
            else
                dis = n - i + upper_bound(x,x+n,x[i]-180+eps) - x - 1;

            ans -= dis*(dis-1)/2;
        }
        printf("Case %d: ",test_count++);
        cout<<ans<<endl;
    }
}
View Code

 

posted @ 2014-03-10 22:32  等待最好的两个人  阅读(278)  评论(0编辑  收藏  举报