LightOJ 1378 - The Falling Circle(几何)

本文介绍了一个涉及几何计算的编程问题解决过程,通过使用C++实现复杂的距离计算和角度计算,最终得出两个圆相交部分的长度及转换为特定单位后的结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

被这题卡了一个月。。因为没有看清题目。。圆在斜线上的速度是角速度为1.我一直以为是一样的速度。。。。。

英语这么挫。过阵子怎么找工作啊。。。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#define LL long long
#define DB double

using namespace std;
const DB PI = acos(-1.0);
struct cycle{
    DB x,y,r;
    void get(){scanf("%lf%lf%lf",&x,&y,&r);}
};
DB dist(cycle a,cycle b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    cycle a,c,b;
    int cas,T=1;scanf("%d",&cas);
    while(cas--)
    {
        a.get();b.get();c.get();
        if(a.y-a.r>b.y-b.r) swap(a,b);
        DB d = dist(a,b);
        DB alph = atan((b.y-a.y)/fabs(b.x-a.x))-asin((b.r-a.r)/d);
        DB low = a.y - a.r/cos(alph);
        DB d1 = c.y - low-fabs(c.x-a.x)*tan(alph)-c.r/cos(alph);
        DB d2;
        if(fabs(a.y-a.r-b.y+b.r)<0.1)
        {
            d2 = 0;
        }else
        {
            DB l1 = sqrt((a.r+c.r)*(a.r+c.r)-(a.r-c.r)*(a.r-c.r));
            d2 = fabs(a.x-c.x)/cos(alph)+c.r*tan(alph)-a.r*tan(alph) - l1;
            d2 = d2/c.r/2/PI;
        }
        printf("Case %d: %.10lf\n",T++,d1+d2);
    }
    return 0;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值