zoukankan      html  css  js  c++  java
  • Codeforces Gym 100338B Geometry Problem 计算几何

    Problem B. Geometry Problem
    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88926#problem/B

    Description

    Peter is studying in the third grade of elementary school. His teacher of geometry often gives him difficult home tasks. At the last lesson the students were studying circles. They learned how to draw circles with compasses. Peter has completed most of his homework and now he needs to solve the following problem. He is given two segments. He needs to draw a circle which intersects interior of each segment exactly once. The circle must intersect the interior of each segment, just touching or passing through the end of the segment is not satisfactory. Help Peter to complete his homework.

    Input

    The input file contains several test cases. Each test case consists of two lines. The first line of the test case contains four integer numbers x11, y11, x12, y12 — the coordinates of the ends of the first segment. The second line contains x21, y21, x22, y22 and describes the second segment in the same way. Input is followed by two lines each of which contains four zeroes these lines must not be processed. All coordinates do not exceed 102 by absolute value.

    Output

    For each test case output three real numbers — the coordinates of the center and the radius of the circle. All numbers in the output file must not exceed 1010 by their absolute values. The jury makes all comparisons of real numbers with the precision of 10−4 .

    Sample Input

    0 0 0 4
    1 0 1 4
    0 0 0 0
    0 0 0 0

    Sample Output

    0.5 0 2

    HINT

    题意

    给你两个线段,让你构造一个圆,与每个线段都只相交一次

    题解

    首先如何判断这个线段和圆相交了一次:一个端点在圆内,一个在圆外

    然后我们枚举四个点的中点,半径就取中点到端点的最小值,然后再随便加上一个0.005就好了

    就AC了……

    加0.05会WA8

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200051
    #define mod 10007
    #define eps 1e-9
    int Num;
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    struct node
    {
        double x,y;
    };
    node kiss1[4];
    node kiss2[4];
    double dis(node a,node b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    int check1(double r,double x,double y)
    {
        int flag=0;
        int flag1=0;
        node ttt;
        ttt.x=x,ttt.y=y;
        for(int i=0;i<2;i++)
        {
            if(dis(ttt,kiss1[i])<r)
                flag++;
            if(dis(ttt,kiss2[i])<r)
                flag1++;
        }
        if(flag==1&&flag1==1)
            return 1;
        return 0;
    }
    int check(double x,double y)
    {
        double ans=inf;
        node a;
        a.x=x,a.y=y;
        for(int i=0;i<2;i++)
        {
            ans = min(ans,dis(a,kiss1[i]));
            ans = min(ans,dis(a,kiss2[i]));
        }
        ans+=0.005;
        if(check1(ans,x,y))
        {
            printf("%.10f %.10f %.10f
    ",x,y,ans);
            return 1;
        }
        return 0;
    }
    int main()
    { 
        srand((unsigned)time(NULL));
        freopen("geometry.in","r",stdin);
        freopen("geometry.out","w",stdout);
        while(1)
        {
            for(int i=0;i<2;i++)
                cin>>kiss1[i].x>>kiss1[i].y;
            for(int i=0;i<2;i++)
                cin>>kiss2[i].x>>kiss2[i].y;
            if(kiss1[0].x==0&&kiss1[0].y==0&&kiss2[0].x==0&&kiss2[0].y==0&&kiss1[1].x==0&&kiss1[1].y==0&&kiss2[1].x==0&&kiss2[1].y==0)
                break;
            node a,b;
            double ans=inf;
            int flag = 1;
            for(int i=0;i<2;i++)
            {
                for(int j=0;j<2;j++)
                {
                    a = kiss1[i],b = kiss2[j];
                    double ansx=(a.x+b.x)/2.0;
                    double ansy=(a.y+b.y)/2.0;
                    if(check(ansx,ansy)==1)
                    {
                        flag = 0;
                        break;
                    }
                }
                if(!flag)
                    break;
            }
            if(!flag)
                continue;
        }
    }
  • 相关阅读:
    看从小自带BUFF的他,如何用代码降低万物互联的门槛
    30亿参数,华为云发布全球最大预训练模型,开启工业化AI开发新模式
    6大新品重磅发布,华为云全栈云原生技术能力持续创新升级
    ISO/IEC 5055:软件代码质量的标尺
    Python基础语法和数据类型最全总结
    40个问题让你快速掌握Java多线程的精髓
    编程实战:如何管理代码里的常量
    总是记不住java的IO流用法?用N个问题教你掌握java IO流
    4种语义分割数据集Cityscapes上SOTA方法总结
    PHP 在Swoole中使用双IoC容器实现无污染的依赖注入
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4748779.html
Copyright © 2011-2022 走看看