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;
}

​

 (代码挺短不是吗)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值