zoukankan      html  css  js  c++  java
  • zoj 3716 计算几何

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3716

    题意:给一个四边形,在每个顶点处画一个圆,要求圆不能重叠,求四个圆最大的半径和。

    思路:一般一点的想法是四个圆里面有三个圆是两两相切,然后枚举最后一个圆。

    这个题我现在也还想不明白。求各位指教。

    下面是传说中世界冠军YY的的思路。

    在矩形中取一三边为a,b,c的三角形,设三相切圆半径为r1,r2,r3.设r1+r2=a,r1+r3=b,r2+r3=c.假设r4与三圆中的R2相切,则{r4+r2=b ,r1+r2=a,r1+r3=b,r2+r3=c }解方程组得r4=(3b-a-c)/2,又因为r1+r2+r3=(a+b+c)/2,所以,r1+r2+r3+r4=2b.同理,与R1,R3相切时r1+r2+r3+r4=2c,r1+r2+r3+r4=2a。

    神代码:

    #include <iostream>
    #include <stdio.h>
    #include <algorithm>
    #include <string.h>
    #include <queue>
    #include <map>
    #include <set>
    #include <vector>
    #include <string>
    #include <math.h>
    using namespace std;
    struct Point
    {
        int x,y;
    }node[4];
    double dis(Point a,Point b)
    {
        return sqrt( (double)(a.x-b.x)*(a.x-b.x)+(double)(a.y-b.y)*(a.y-b.y) );
    }
    
    
    int main()
    {
    //    freopen("in.txt","r",stdin);
    //    freopen("out.txt","w",stdout);
        while(scanf("%d%d",&node[0].x,&node[0].y)==2)
        {
            for(int i=1;i<4;i++)
                scanf("%d%d",&node[i].x,&node[i].y);
            double d1=dis(node[0],node[1]);
            double d2=dis(node[1],node[2]);
            double d3=dis(node[2],node[3]);
            double d4=dis(node[0],node[3]);
            double d5=dis(node[0],node[2]);
            double d6=dis(node[3],node[1]);
    
            double ans = min(d1+d3,min(d2+d4,d5+d6));
            printf("%.8lf
    ",ans);
    
        }
        return 0;
    }
    究竟是我抛弃了历史,还是历史遗弃了我。
  • 相关阅读:
    GoogleTest 之路2-Googletest 入门(Primer)
    GoogleTest 之路1-Generic Build Instructions编译指导总方案
    Tinyhttpd 知识点
    栈初始化
    ARM S3C2440 时钟初始化流程
    GNU 关闭 MMU 和 Icache 和 Dcache
    bootloader 关闭看门狗
    bootloader svc 模式
    Uboot S3C2440 BL1 的流程
    GNU 汇编 协处理器指令
  • 原文地址:https://www.cnblogs.com/54zyq/p/3203649.html
Copyright © 2011-2022 走看看