zoukankan      html  css  js  c++  java
  • noip模拟赛 站军姿

    分析:纯数学题.相离和包含关系的可以很容易算出来答案,相交的话要先求出两个圆的面积,然后减掉中间重叠的部分,这一部分并不能直接求出来,但是可以求出两个扇形的面积,和它们围成的一个四边形的面积,加加减减就出来了.利用到了acos函数,返回来的是弧度制!

    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    double pai = 3.14159265358979323846264;
    int T;
    double x1, y3, r1, x2, y2, r2, ans;
    
    int main()
    {
        scanf("%d", &T);
        while (T--)
        {
            scanf("%lf%lf%lf%lf%lf%lf", &x1, &y3, &r1, &x2, &y2, &r2);
            double d = sqrt((x1 - x2) * (x1 - x2) + (y3 - y2) * (y3 - y2));
            if (r1 + r2 <= d)
                printf("%.3lf
    ", pai*(r1 * r1 + r2 * r2));
            else
                if (abs(r1 - r2) >= d)
                    printf("%.3lf
    ", pai*(max(r1, r2)*max(r1, r2)));
                else
                {
                    double A = acos((r1*r1 + d * d - r2 * r2) / (2 * r1 * d));
                    double B = acos((r2*r2 + d*d - r1*r1) / (2 * r2*d));
                    ans = pai*(r1*r1 + r2*r2);
                    ans -= A*r1*r1 + B*r2*r2;
                    ans += d * sin(A) * r1;
                    printf("%.3lf
    ", ans);
                }
        }
    
        return 0;
    }
  • 相关阅读:
    函数的定义
    编码转换
    bytes类型
    用py操作文件(file类的功能)
    HASH哈希
    二进制、bit、 bytes
    POJ3225
    POJ1436
    HDU1394
    HDU1272
  • 原文地址:https://www.cnblogs.com/zbtrs/p/7721760.html
Copyright © 2011-2022 走看看