Keyboard Free (计算几何)2020牛客多校第二场

题目描述 

Given three concentric circles whose radiuses are r_1, r_2, r_3r1​,r2​,r3​ respectively, and {A,B,C}A,B,C are the moving points on the given three circles respectively. Determine the expected area of \triangle ABC△ABC.

输入描述:

The first line contains one integer T~(1 \leq T \leq 1000)T (1≤T≤1000), denoting the number of test cases.
For each test case:
One line containing three integers r_1, r_2, r_3~(1\leq r_1,r_2,r_3 \leq 100)r1​,r2​,r3​ (1≤r1​,r2​,r3​≤100), denoting the radiuses of three given concentric circles.

输出描述:

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

示例1

输入

2
1 1 1
2 3 5

输出

0.5
5.5

说明

For test case 1, the accurate answer is \frac{3}{2\pi} = 0.47746482927568600730665129011754\cdots2π3​=0.47746482927568600730665129011754⋯.

首先感谢“世界第一中单”cyt上午的教学!

思路:先对输入的r1,r2,r3进行排序,r1 <=r2 <=r3

因为可以对3个圆进行旋转,默认r1上的点不变为(r1,0),将r2圆分为1000份并遍历上面的点(x,y)

之后如下:

代码:

​
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
double r1, r2, r3;
int main() {
    int t;
    cin>>t;
    while(t--)
    {
        cin>>r1>>r2>>r3;
        if (r1 > r2) swap(r1, r2);
        if (r2 > r3) swap(r2, r3);
        if (r1 > r2) swap(r1, r2);
        double e = 2.0 * pi / 1000;
        double ans = 0;
        for (int i = 1; i <= 1000; i++) {
            double b = i * e, x = r2 * cos(b), y = r2 * sin(b);
            double l = sqrt((x - r1) * (x - r1) + y * y);
            double h=r1*y/l;
            double a=asin(h/r3);
            double Eh=(2*r3*cos(a)+2*a*h)/pi;
            ans += 0.5 * l * Eh;
        }
        printf("%.1f\n", ans / 1000);
    }
    return 0;
}

​

 (代码挺短不是吗)

全部评论

相关推荐

找工作勤劳小蜜蜂:矛盾是没有实习,就是没实战经验,公司不想要,公司不要,你就没有实习,你就进入死循环,另外你的项目不是社会现在有大量岗位存在行业用的,云存储人员早就饱和。
点赞 评论 收藏
分享
1jian10:48h没写面评会变成这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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