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

​

 (代码挺短不是吗)

全部评论

相关推荐

LazyBreeze:项目尽量体现你对技术的理解和深度,不是说把中间件用一下就完事了,你项目里面提到集群和分布式,你真在服务器上部署过吗,感觉太假了,第二个项目说自己用了微服务的什么组件,只是用了没有自己的思考,很难让面试官注意到你的简历。针对某几个技术点自己多思考一下,考虑一下有没有别的替代方案,可以写一下,即使没有真的实现
点赞 评论 收藏
分享
07-11 22:27
中南大学 Java
程序员牛肉:学历的话没问题。但是没问题的也就只有学历了。 其实你的整体架构是正确的,博客接着干。但是项目有点过于简单了。从后端的角度上讲,你这也就是刚入门的水平,所以肯定约面试够呛。 如果你要应聘后端岗位,那你第一个项目竟然是仿写操作系统。这个你要面试官咋问你。你一定要记住一点,你简历上写的所有的东西,都是为了证明你有能力胜任当前的岗位,而不是为了证明你自己会什么。 如果你只是浅浅的做几个项目,描述也都是烂大街。技术点也都是各种混水类的配置类需求,那你就不要幻想自己能走多远。一定要保持思考,保持学习。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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