2017多校第6场 HDU 6097 Mindis 计算几何,圆的反演

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6097

题意:有一个圆心在原点的圆,给定圆的半径,给定P、Q两点坐标(PO=QO,P、Q不在圆外),取圆上一点D,求PD+QD的最小值。

解法:圆的反演。

很不幸不总是中垂线上的点取到最小值,考虑点在圆上的极端情况。

做P点关于圆的反演点P‘,OPD与ODP‘相似,相似比是|OP| : r。

Q点同理。

极小化PD+QD可以转化为极小化P‘D+Q‘D。

当P‘Q‘与圆有交点时,答案为两点距离,否则最优值在中垂线上取到。

时间复杂度 O(1)

也有代数做法,结论相同。

优秀的黄金分割三分应该也是可以卡过的。

分析可以看这个博客:http://blog.csdn.net/qq_34845082/article/details/77099332

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct FastIO
{
    static const int S = 1310720;
    int wpos;
    char wbuf[S];
    FastIO() : wpos(0) {}
    inline int xchar()
    {
        static char buf[S];
        static int len = 0, pos = 0;
        if(pos == len)
            pos = 0, len = fread(buf, 1, S, stdin);
        if(pos == len)
            exit(0);
        return buf[pos ++];
    }
    inline unsigned long long xuint()
    {
        int c = xchar();
        unsigned long long x = 0;
        while(c <= 32)
            c = xchar();
        for(; ‘0‘ <= c && c <= ‘9‘; c = xchar())
            x = x * 10 + c - ‘0‘;
        return x;
    }
    inline long long xint()
    {
        long long s = 1;
        int c = xchar(), x = 0;
        while(c <= 32)
            c = xchar();
        if(c == ‘-‘)
            s = -1, c = xchar();
        for(; ‘0‘ <= c && c <= ‘9‘; c = xchar())
            x = x * 10 + c - ‘0‘;
        return x * s;
    }
    inline void xstring(char *s)
    {
        int c = xchar();
        while(c <= 32)
            c = xchar();
        for(; c > 32; c = xchar())
            * s++ = c;
        *s = 0;
    }
    inline double xdouble()
    {
        bool sign = 0;
        char ch = xchar();
        double x = 0;
        while(ch <= 32)
            ch = xchar();
        if(ch == ‘-‘)
            sign = 1, ch = xchar();
        for(; ‘0‘ <= ch && ch <= ‘9‘; ch = xchar())
            x = x * 10 + ch - ‘0‘;
        if(ch == ‘.‘)
        {
            double tmp = 1;
            ch = xchar();
            for(; ch >= ‘0‘ && ch <= ‘9‘; ch = xchar())
                tmp /= 10.0, x += tmp * (ch - ‘0‘);
        }
        if(sign)
            x = -x;
        return x;
    }
    inline void wchar(int x)
    {
        if(wpos == S)
            fwrite(wbuf, 1, S, stdout), wpos = 0;
        wbuf[wpos ++] = x;
    }
    inline void wint(long long x)
    {
        if(x < 0)
            wchar(‘-‘), x = -x;
        char s[24];
        int n = 0;
        while(x || !n)
            s[n ++] = ‘0‘ + x % 10, x /= 10;
        while(n--)
            wchar(s[n]);
    }
    inline void wstring(const char *s)
    {
        while(*s)
            wchar(*s++);
    }
    inline void wdouble(double x, int y = 8)
    {
        static long long mul[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000LL, 100000000000LL, 1000000000000LL, 10000000000000LL, 100000000000000LL, 1000000000000000LL, 10000000000000000LL, 100000000000000000LL};
        if(x < -1e-12)
            wchar(‘-‘), x = -x;
        x *= mul[y];
        long long x1 = (long long) floorl(x);
        if(x - floor(x) >= 0.5)
            ++x1;
        long long x2 = x1 / mul[y], x3 = x1 - x2 * mul[y];
        wint(x2);
        if(y > 0)
        {
            wchar(‘.‘);
            for(size_t i = 1; i < y && x3 * mul[i] < mul[y]; wchar(‘0‘), ++i);
            wint(x3);
        }
    }
    ~FastIO()
    {
        if(wpos)
            fwrite(wbuf, 1, wpos, stdout), wpos = 0;
    }
} io;

const double eps = 1e-8;
double getDis(double x, double y){
    return sqrt(x*x+y*y);
}
double r,x1,y1,x2,y2;

int main()
{
    int T = io.xint();
    while(T--)
    {
        r = io.xdouble();
        x1 = io.xdouble();
        y1 = io.xdouble();
        x2 = io.xdouble();
        y2 = io.xdouble();
        double d0 = getDis(x1, y1);
        if(fabs(d0)<=eps){//p和q和原点重合
            printf("%.8f\n", 2*r);
            continue;
        }
        double k = r*r/d0/d0;//用这个比例确定p和q的反演点
        double x3=x1*k, x4=x2*k;
        double y3=y1*k, y4=y2*k;
        double mx=(x3+x4)/2.0,my=(y3+y4)/2.0;
        double ans;
        double d = getDis(mx, my);
        if(d <= r){//判断反演点和半径的关系 如果两个反演点的中点到圆心的距离小于半径
            double dis = getDis(x3-x4,y3-y4);
            ans = dis*d0/r;
        }
        else{//其他的即是连线与圆相离时的状态 这时候的d点是p和q的反演点的连线的中垂线与圆的交点
            double kk=r/d;//其他的即是连线与圆相离时的状态 这时候的d点是p和q的反演点的连线的中垂线与圆的交点
            double smx = mx*kk, smy = my*kk;
            ans = 2*getDis(smx-x1,smy-y1);
        }
        printf("%.8f\n", ans);
    }
    return 0;
}
时间: 2024-08-06 03:20:24

2017多校第6场 HDU 6097 Mindis 计算几何,圆的反演的相关文章

2017多校第8场 HDU 6143 Killer Names 容斥,组合计数

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6143 题意:m种颜色需要为两段长度为n的格子染色,且这两段之间不能出现相同的颜色,问总共有多少种情况. 解法:枚举要为这两段分配的颜色数目分别为 i,j ,则在第一段总共有 C(m,i) 种选取方案,在第二段总共有 C(m?i,j) 种选取方案.而在每段内部,我们设 F(n,x) 为长度为 n 的格子使用 x 种颜色(等于 x )染色的方案数.则根据容斥原理 F(n,x)=x^n?C(x,1)*(x

2017多校第4场 HDU 6078 Wavel Sequence DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6078 题意:求两个序列的公共波形子序列的个数. 解法: 类似于最长公共上升子序列,对于每个i,只考虑存在j使得a[i]==b[j]的情况. dp[i][j][0]表示以a[i]和b[j]为公共序列结尾且为波谷的情况总和. dp[i][j][1]则表示波峰的情况总和. S[i][j][0]表示sum(dp[k][j][0] | 1<=k<=j-1). S[i][j][1]则表示sum(dp[k][j

2017多校第7场 HDU 6129 Just do it 找规律

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6129 题意:求a序列后m次xor前缀和 解法: 手动对1位置对每个位置的贡献打表发现 第一次 贡献为 1 1 1 1 1 1 1 1 1 1 1 第二次 贡献为 1 0 1 0 1 0 1 0 1 0 1 0 第四次 贡献为 1 3个0 1 3个0 1 3个0 1 3个0 第八次 贡献为 1 7个0 1 7个0 1 7个0 1 7个0 ... 这是比赛之后才知道的,看着比赛的时候通过了200+人,被

2017多校第10场 HDU 6180 Schedule 贪心,multiset

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并且使得机器的运行时间的和最小. 解法:按开始工作的时间从小到大排序后,用一个set容器维护一下,每次加入找set里面结束时间小于等于开始时间并且最近的点插入即可,然后如果没有小于开始时间的就重新开一台机器即可,这里可能有重复元素,需要multiset. #include <bits/stdc++.h

2017多校第9场 HDU 6170 Two strings DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6170 题意:给了2个字符串,其中第2个字符串包含.和*两种特别字符,问第二个字符串能否和第一个匹配. 解法:dp[i][j]代表在第一个串的i位置,第2个串的j位置是否可以匹配,然后按照'*'这个特殊情况讨论转移即可. #include <bits/stdc++.h> using namespace std; const int maxn = 3005; bool dp[maxn][maxn];

2017多校第10场 HDU 6181 Two Paths 次短路

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6181 题意:给一个图,求出次短路. 解法:我之前的模板不能解决这种图,就是最短路和次短路相等的情况,证明这题数据还是水了.下来我修改了一下次短路的,就可以避免这种情况了.提供一个sample 4 4 (1,2,1)( 1, 3,1) (2 4,1) (3 ,4,1).这组的正确答案是2,算法就来看代码吧. #include <bits/stdc++.h> using namespace std;

2017多校第8场 HDU 6134 Battlestation Operational 莫比乌斯反演

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134 题意: 解法: 那么g(n)怎么求,我们尝试打表发现g(n)是有规律的,g(n)=g(n-1)+d(n-1)+1,其中d(i)表示i的因子个数,这个我们是可以通过线性筛O(n)处理出来的,之后再O(n)维护g(i)的前缀和,就可以在单组sqrt(n)的复杂度下得到答案了. #include <bits/stdc++.h> using namespace std; typedef long l

2017多校第10场 HDU 6172 Array Challenge 猜公式,矩阵幂

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6172 题意:如题. 解法: #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL mod = 1e9+7; struct Matrix{ LL a[3][3]; void set1(){ memset(a, 0, sizeof(a)); } void set2(){ memset(a, 0, siz

2017多校第10场 HDU 6178 Monkeys 贪心,或者DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只猴子必有一只另外的猴子通过一条边与它相连,问最少用多少条边能达到这个要求. 解法:利用贪心的思维,显然我们应该先选择性价比最高的,即一条边连接两个点的情况.计算出这样的边的条数ans,如果ans*2>=k,结果就是(k+1)/2,否则剩下来没有安排的猴子每一只需要多一条边,即结果为ans+k-2 *