CF 333E Summer Earnings

Posted cq.tiancx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF 333E Summer Earnings相关的知识,希望对你有一定的参考价值。

题目: Summer Earnings ,哈哈,我们今天来看一道稍微复杂一点的题嘛,这是选自codeforce上的一道题,好了,我们一起来看看题意吧:

题目描述是复制的,可能有部分显示不对,我就把题目链接放下面!
题目链接: Summer Earnings

题目描述

Many schoolchildren look for a job for the summer, and one day, when Gerald was still a schoolboy, he also decided to work in the summer. But as Gerald was quite an unusual schoolboy, he found quite unusual work. A certain Company agreed to pay him a certain sum of money if he draws them three identical circles on a plane. The circles must not interfere with each other (but they may touch each other). He can choose the centers of the circles only from the n options granted by the Company. He is free to choose the radius of the circles himself (all three radiuses must be equal), but please note that the larger the radius is, the more he gets paid.
Help Gerald earn as much as possible.

输入描述

The first line contains a single integer n — the number of centers (3 ≤ n ≤ 3000). The following n lines each contain two integers xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of potential circle centers, provided by the Company.

输出描述

Print a single real number — maximum possible radius of circles. The answer will be accepted if its relative or absolute error doesn’t exceed 10 -6.

示例1

输入

3
0 1
1 0
1 1

输出

0.50000000000000000000

示例2

输入

7
2 -3
-2 -3
3 0
-3 -1
1 -2
2 -2
-1 0

输出

1.58113883008418980000

思路:

思路就看代码吧,有注释的!

我们来看看成功AC的代码吧:

#include<iostream>
#include<cmath>
#include<bitset>
#include<algorithm>
#include<iomanip>
using namespace std;
int x[3010],y[3010];
int m,n;
bitset<4000> b[4000];
struct Edge
    int len;
    int xx,yy;
a[3000*3000];
//计算两点的距离,我们这里先不开根号,以免有误
int dist(int i,int j)      return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]); 
//将边按照从大到小排序的cmp函数
int cmp(Edge e1,Edge e2)      return e1.len>e2.len;   
int main()
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            a[++m].len=dist(i,j);//i点到j点的距离
            a[m].xx=i;
            a[m].yy=j;
        
    sort(a+1,a+1+m,cmp);//将边按照从大到小排序
    for(int i=1;i<=m;i++)
        if((b[a[i].xx]&b[a[i].yy])!=0)//xx 和 yy 连在了同一个点上,则输出答案     	
            cout<<fixed<<setprecision(8)<<sqrt(a[i].len)/2.0; 
            return 0;
        else
            //将xx于yy连接起来,就是加入了xx-yy这条边
            b[a[i].xx][a[i].yy]=1;
            b[a[i].yy][a[i].xx]=1;
        
    
    return 0;

谢谢你的阅读,由于作者水平有限,难免有不足之处,若读者发现问题,还请批评,在留言区留言或者私信告知,我一定会尽快修改的。若各位大佬有什么好的解法,或者有意义的解法都可以在评论区展示额,万分谢谢。
写作不易,望各位老板点点赞,加个关注!

以上是关于CF 333E Summer Earnings的主要内容,如果未能解决你的问题,请参考以下文章

E. Summer Earnings

CF538H Summer Dichotomy

CF538H Summer Dichotomy 二分图扫描线线段树

CF 1039D You Are Given a Tree && CF1059E Split the Tree 的贪心解法

CF #610Div2 B2.K for the Price of One (Hard Version) (dp解法 && 贪心解法)

CF 40E[Number Table]