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;
}
牛客暑期多校训练营题解 文章被收录于专栏

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

全部评论

相关推荐

10-30 19:23
已编辑
山东大学(威海) C++
牛至超人:我了个雷 1.实习经历写太长了吧,精简一点,你写那么老多,面试官看着都烦 2.项目经历你放俩竞赛干啥单独拿出来写上几等奖就行了呗 3.一大雷点就是项目经历里的那个课程设计,大家都知道课程设计巨水,不要写课程设计,换一个名字,就叫学生管理系统,面试官问就说是自己做的项目,不要提课程设计的事 4.那个交流经历,简化一下塞到最上面的教育经历里就行了 5.简历尽量一页纸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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