DES:给出n条线段。询问每次射中线段条数的期望。

非常简单。就是每条线段的两端与原点相连的直线之间的夹角和。如果夹角大于pi。就是2pi减去这个角。最后除以总值2pi就是所求的期望。

atan2(y, x)。表示指向(y, x)的射线和x轴正向组成的夹角。

不知道比赛的时候是不是也能想到。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
    int t;
    double pi = 3.1415926;
    scanf("%d", &t);
    while(t--)
    {
        int n;
        scanf("%d", &n);
        int x1, y1, x2, y2;
        double ans = 0.0;
        double temp;
        while(n--)
        {
            scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
            temp = fabs(atan2(y1, x1) - atan2(y2, x2));
            if (temp > pi) temp = 2*pi - temp;
            ans += temp;
        }
        ans /= 2*pi;
        printf("%.5lf\n", ans);
    }
}
LOoK

 

posted on 2015-08-02 21:01  小小八  阅读(215)  评论(0编辑  收藏  举报