CF 333E Summer Earnings

简介: 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;
}


相关文章
|
6月前
|
算法
CF 1561
【7月更文挑战第20天】
56 2
DFS56L TF RH1M KK ABB 120 TAS.580.0560G00
DFS56L TF RH1M KK ABB 120 TAS.580.0560G00
61 0
|
人工智能
CF628B
CF628B
77 0
|
人工智能
cf 220B(莫队)
cf 220B(莫队)
104 0
|
人工智能 网络架构
CF 698A
CF 698A
82 0
CF611C New Year and Domino
CF611C New Year and Domino
86 0