2020牛客暑期多校训练营(第二场)K

Keyboard Free

https://ac.nowcoder.com/acm/contest/5667/K

题目描述

  Given three concentric circles whose radiuses are respectively, and are the moving points on the given three circles respectively. Determine the expected area of .

输入描述

  The first line contains one integer , denoting the number of test cases.
  For each test case, one line containing three integers , denoting the radiuses of three given concentric circles.

输出描述

  Print lines each containing one real number with one decimal places after the decimal point, denoting the answer to corresponding test case.
  It's guaranteed that the second decimal place after the decimal point is neither nor .

示例1

输入

2
1 1 1
2 3 5

输出

0.5
5.5

说明

  For the first text case, the accurate answer is .

分析

  由于 只与 三点的相对位置有关,可以将 视作顶点, 为动点。不妨以同心圆的圆心作为原点建立平面直角坐标系,令 ,且
  利用向量的叉积计算面积

  设出现极角 的概率为 ,则 的期望为

  此题精度要求较低,不妨将 分成 份,每份的角度为 ,那么 。可直接用矩形法求积分的近似数值解,设置步长为 ,枚举 内的所有角度即可。

代码

/******************************************************************
Copyright: 11D_Beyonder All Rights Reserved
Author: 11D_Beyonder
Problem ID: 2020牛客暑期多校训练营(第二场) Problem K
Date: 8/4/2020
Description: Expectation and Integral
*******************************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int t=400;
const double pi=acos(-1);
double _sin[t+1],_cos[t+1];
int main()
{
    int i,j,_;
    const double step=2*pi/t;
    double theta=0;
    for(i=1;i<=t;i++)
    {
        _sin[i]=sin(theta);
        _cos[i]=cos(theta);
        theta+=step;
    }
    for(cin>>_;_;_--)
    {
        double r1,r2,r3;
        scanf("%lf%lf%lf",&r1,&r2,&r3);
        //=====================
        //排序
        if(r1>r2) swap(r1,r2);
        if(r2>r3) swap(r2,r3);
        if(r1>r3) swap(r1,r3);
        //=====================
        //矩形法 
        //枚举 t*t 个角度组合
        double ans=0;
        for(i=1;i<=t;i++)
        {
            for(j=1;j<=t;j++)
            {
                ans+=fabs((r2*_cos[i]-r1)*r3*_sin[j]-(r3*_cos[j]-r1)*r2*_sin[i]);
            }
        }
        printf("%.1lf\n",ans/2/t/t);
    }
    return 0;
}
牛客暑期多校训练营题解 文章被收录于专栏

收集牛客暑期多校训练营的题解

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:24
大家还是用ai改吧,我心疼得要死,就当花钱买教训吧,人家直接拿完钱就跑路了
程序员小白条:简历修改700....神奇,又不是帮你面试,咋的,简历修改从双非变92了还是没实习变成有大厂实习了
点赞 评论 收藏
分享
07-10 14:08
已编辑
江西农业大学 Java
念旧select:做完把项目放到自己硬盘里给他看,看完拷走
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务