zoukankan      html  css  js  c++  java
  • UVSLive 6324 求射箭覆盖的期望

    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
    ", ans);
        }
    }
    LOoK
  • 相关阅读:
    变量作用域
    模块化编程-函数
    递归
    变量
    形参和实参
    函数返回值
    node.js+yarn环境centos7快速部署
    LINUX磁盘添加挂载
    分布式存储MINIO集群部署实例
    Docker取消默认https连接
  • 原文地址:https://www.cnblogs.com/icode-girl/p/4696721.html
Copyright © 2011-2022 走看看