TOJ 4080 find the princessIII(圆和直线相交)

这是一道编程题,描述了Dsir需要判断公主是否会被炸弹影响的情景。输入包括炸弹位置、半径及公主所在棍子两端坐标,输出公主所处状态。

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

4080.   find the princessIII
Time Limit: 1.0 Seconds   Memory Limit:65536K
Total Runs: 613   Accepted Runs:118



It is a pity that the Dsir cost much time in "find the princess II". The devil has dropped a bomb beside the princess.This is the scope of bomb is a circle. The radius of the circle is R. The bomb can be regarded as a point. The coordinates of cirle is (cx, cy). For this problem,we can assume that the princess was tied to a stick. The coordinates of stick two endpoints is (x1, y1), (x2,y2). Dsir want to know whether the princess would be Fried.

Input

First line of input T(the number of cases), each line of input cx, cy, R, x1, y1, x2, y2.
-100≤cx≤100,-100≤cy≤100,-100≤x1≤100, -100≤y1≤100, -100≤x2≤100, -100≤y2≤100, -100≤R≤100

Output

For each case, output "All in"(the princess completely within the circle) OR "Part in"(the princess parts within the circle) OR "All out"(the princess not in the circle).

Hint:
If stick with only one point on the circle, is considered to be the princess is not in the circle!

Sample Input

3

0 0 1 0 0 0 1

0 0 1 0 0 1 1

0 0 1 1 0 1 1

Sample Output

All in

Part in

All out 


#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const double eps=1e-7;
int sgn(double x)
{
    if(x<-eps)return -1;
    if(x>eps)return 1;
    return 0;
}
typedef struct vec
{
    double x,y;
    vec(double xa,double ya)
    {
        x=xa,y=ya;
    }
    vec operator - (vec v)
    {
        return vec(x-v.x,y-v.y);
    }
    double operator * (vec v)
    {
        return x*v.x+y*v.y;
    }
    double len()
    {
        //printf("%f %f %f\n",x,y,hypot(x,y));
        return hypot(x,y);
    }
}vec;
double cross(vec a,vec b)
{
    return a.x*b.y-a.y*b.x;
}
double dist_point_to_segment(vec p,vec a,vec b)
{
    if(sgn((p-a)*(b-a))>=0&&sgn((p-b)*(a-b))>=0)return fabs(cross(p-a,b-a))/(b-a).len();
    return min((p-a).len(),(p-b).len());
}
int main()
{
    double xa,ya,xb,yb,xc,yc,R;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf",&xc,&yc,&R,&xa,&ya,&xb,&yb);
        double dist=dist_point_to_segment(vec(xc,yc),vec(xa,ya),vec(xb,yb));
        double dist2=max(vec(xa-xc,ya-yc).len(),vec(xb-xc,yb-yc).len());
        //printf("%f %f %f\n",dist,dist2,R);
        if(dist2<=R+eps)
        {
            printf("All in\n");
        }
        else
        {
            if(dist+eps>R)
            {
                //printf("%f %f \n",dist+eps,R);
                printf("All out\n");
            }
            else printf("Part in\n");
        }
        //if(T)printf("\n");
    }
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值