L.手动计算(思维)

题干

https://ac.nowcoder.com/acm/contest/17148/L

题意

平面上有两个椭圆,一个焦点在 x 轴上,一个焦点在 y 轴上,求这两个椭圆面积的并的大小,保留一位小数。
数据组数 T (1<=T<=5),椭圆与 x 轴、y 轴 的交点在区间 [-8, 8] 上。

思路

将两椭圆组合图形的横坐标分成20000份,则图形近似由20000个矩形组成。若横坐标区间长度为 2a ,则从 x==-a 开始,每次加 a/10000(即矩形的宽),x 带入椭圆公式求得矩形高,矩形面积之和即所求面积。

代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
using namespace std;

typedef long long ll;

const int N = 1e3+10;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        double a,b,c,d;
        scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
        double x, p = max(a, c)/10000.0, ans = 0.0;
        if(a>=c){
            x = -a;
            while(x<a){
                if(x>=-c&&x<=c)
                    ans+=p*max(sqrt(b*b*(1.0-x*x/(a*a))), sqrt(d*d*(1.0-x*x/(c*c))));
                else
                    ans+=p*sqrt(b*b*(1.0-x*x/(a*a)));
                x+=p;
            }
        }else{
            x = -c;
            while(x<c){
                if(x>=-a&&x<=a)
                    ans+=p*max(sqrt(b*b*(1.0-x*x/(a*a))), sqrt(d*d*(1.0-x*x/(c*c))));
                else
                    ans+=p*sqrt(d*d*(1.0-x*x/(c*c)));
                x+=p;
            }
        }
        ans*=2;
        printf("%.1f\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值