BZOJ 2280 Poi2011 Plot 二分答案+随机增量法

题目大意:给定n个点,要求分成m段,使每段最小覆盖圆半径的最大值最小

二分答案,然后验证的时候把点一个个塞进最小覆盖圆中,若半径超了就分成一块……

等等你在跟我说不随机化的随机增量法?

好吧

那么对于一个点pos,我们要计算最大的bound满足[pos,bound]区间内的最小覆盖圆半径不超过二分的值

直接上二分是不可取的,因为我们要求m次,如果每次都验证一遍[1,n/2]直接就炸了

我们可以这么搞

首先判断[pos,pos+1-1]是否满足要求

然后判断[pos,pos+2-1]是否满足要求

然后判断[pos,pos+4-1]是否满足要求

然后判断[pos,pos+8-1]是否满足要求

...

直到找到一个不满足要求2^k的为止,然后我们在[2^(k-1),2^k]区间内二分

这样可以保证复杂度为O(nlognlog(limit/eps)) 不过常数巨大。。。。

居然直接A了 没卡掉OJ真是差评

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define M 100100
#define EPS 1e-10
using namespace std;
typedef long double ld;
struct Point{
    ld x,y;
    Point() {}
    Point(ld _,ld __):
        x(_),y(__) {}
    friend istream& operator >> (istream &_,Point &p)
    {
        double x,y;
        scanf("%lf%lf",&x,&y);
        p.x=x;p.y=y;
        return _;
    }
    friend Point operator + (const Point &p1,const Point &p2)
    {
        return Point(p1.x+p2.x,p1.y+p2.y);
    }
    friend Point operator - (const Point &p1,const Point &p2)
    {
        return Point(p1.x-p2.x,p1.y-p2.y);
    }
    friend ld operator * (const Point &p1,const Point &p2)
    {
        return p1.x*p2.y-p1.y*p2.x;
    }
    friend Point operator * (const Point &p,ld rate)
    {
        return Point(p.x*rate,p.y*rate);
    }
    friend ld Distance(const Point &p1,const Point &p2)
    {
        return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) ) ;
    }
    friend Point Rotate(const Point &p)
    {
        return Point(-p.y,p.x);
    }
}points[M];
struct Line{
    Point p,v;
    Line() {}
    Line(const Point &_,const Point &__):
        p(_),v(__) {}
    friend Point Get_Intersection(const Line &l1,const Line &l2)
    {
        Point u=l1.p-l2.p;
        ld temp=(l2.v*u)/(l1.v*l2.v);
        return l1.p+l1.v*temp;
    }
};
struct Circle{
    Point o;
    ld r;
    Circle() {}
    Circle(const Point &_,ld __):
        o(_),r(__) {}
    bool In_Circle(const Point &p)
    {
        return Distance(p,o) < r + EPS ;
    }
};
int n,m;
Circle Min_Circle_Cover(int l,int r)
{
    static Point points[M];
    int i,j,k;
    Circle ans(Point(0,0),0);
    memcpy(points+l,::points+l,sizeof(Point)*(r-l+1));
    random_shuffle(points+l,points+r+1);
    for(i=l;i<=r;i++)
        if(!ans.In_Circle(points[i]))
        {
            ans=Circle(points[i],0);
            for(j=l;j<i;j++)
                if(!ans.In_Circle(points[j]))
                {
                    ans=Circle((points[i]+points[j])*0.5,Distance(points[i],points[j])*0.5);
                    for(k=l;k<j;k++)
                        if(!ans.In_Circle(points[k]))
                        {
                            Line l1=Line((points[i]+points[j])*0.5,Rotate(points[i]-points[j]));
                            Line l2=Line((points[i]+points[k])*0.5,Rotate(points[i]-points[k]));
                            Point p=Get_Intersection(l1,l2);
                            ans=Circle(p,Distance(p,points[i]));
                        }
                }
        }
    return ans;
}
int Extend(int pos,ld limit)
{
    int i;
    for(i=1;;i=min(i<<1,n-pos+1))
    {
        if(Min_Circle_Cover(pos,pos+i-1).r>limit+EPS)
            break;
        if(i==n-pos+1) return n;
    }
    int l=pos+(i>>1)-1,r=pos+i-1;
    while(l+1<r)
    {
        int mid=l+r>>1;
        if(Min_Circle_Cover(pos,mid).r<limit+EPS)
            l=mid;
        else
            r=mid;
    }
    return l;
}
bool Judge(ld limit)
{
    int i,last,cnt=0;
    for(i=1;i<=n;i=last+1)
    {
        if(++cnt==m+1)
            return false;
        last=Extend(i,limit);
    }
    return true;
}
ld Bisection()
{
    ld l=0,r=Min_Circle_Cover(1,n).r;
    while(r-l>EPS)
    {
        ld mid=(l+r)/2;
        if( Judge(mid) )
            r=mid;
        else
            l=mid;
    }
    return r;
}
void Output(double limit)
{
    static Point stack[M];
    int i,last,top=0;
    for(i=1;i<=n;i=last+1)
    {
        last=Extend(i,limit);
        stack[++top]=Min_Circle_Cover(i,last).o;
    }
    cout<<top<<endl;
    for(i=1;i<=top;i++)
        printf("%.15lf %.15lf\n",(double)stack[i].x,(double)stack[i].y);
}
int main()
{
    int i;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        cin>>points[i];
    ld ans=Bisection();
    cout<<fixed<<setprecision(15)<<ans<<endl;
    Output(ans+EPS);
    return 0;
}
时间: 2025-01-02 01:27:50

BZOJ 2280 Poi2011 Plot 二分答案+随机增量法的相关文章

BZOJ 2525 Poi2011 Dynamite 二分答案+树形贪心

题目大意:给定一棵树,有一些点是关键点,要求选择不超过m个点,使得所有关键点到最近的选择的点距离最大值最小 二分答案,问题转化为: 给定一棵树,有一些点是关键点,要求选择最少的点使得每个关键点到选择的点的距离不超过limit 然后我们贪心DFS一遍 对于以一个节点为根的子树,有三种状态: 0.这棵子树中存在一个选择的点,这个选择的点的贡献还能继续向上传递 1.这棵子树中存在一个未被覆盖的关键点,需要一些选择的点去覆盖他 2.这棵子树中既没有能继续向上传递的选择的点也不存在未覆盖的关键点 是不是少

BZOJ 1337 最小圆覆盖 随机增量法

题意:链接 方法:随机增量法 解析: 首先把所有点打乱. 然后枚举第一个点,如果不在当前的圆内则把它设为圆心. 再枚举第二个点,如果不在当前的圆内则把圆设为其与第一个点的距离为直径的圆. 再枚举第三个点,如果不在当前的圆内则把圆设为这三个点构成三角形的外接圆. 然后最后就是答案了. 别问我这为什么是对的- -! 复杂度期望O(n),我是信了. 代码: #include <cmath> #include <cstdio> #include <iomanip> #inclu

BZOJ 1336 Balkan2002 Alien最小圆覆盖 随机增量法

题目大意:求最小圆覆盖 随机增量法裸题 注意多输出几位小数不然过不去= = #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define M 100100 #define EPS 1e-7 using namespace std; struct Point

【BZOJ-1336&amp;1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)

1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1573  Solved: 697[Submit][Status][Discuss] Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0) Outpu

【bzoj1336/1337/2823】[Balkan2002]Alien最小圆覆盖 随机增量法

题目描述 给出N个点,让你画一个最小的包含所有点的圆. 输入 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0) 输出 输出圆的半径,及圆心的坐标 样例输入 6 8.0 9.0 4.0 7.5 1.0 2.0 5.1 8.7 9.0 2.0 4.5 1.0 样例输出 5.00 5.00 5.00 题解 随机增量法求最小圆覆盖裸题 求法:设初始圆为某空圆,先枚举第一个点,如果不在当前圆内,则令当前圆为这一个点的最小圆

【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法

[BZOJ1336][Balkan2002]Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0) Output 输出圆的半径,及圆心的坐标 Sample Input 6 8.0 9.0 4.0 7.5 1.0 2.0 5.1 8.7 9.0 2.0 4.5 1.0 Sample Output 5.00 5.00 5

BZOJ 1816: [Cqoi2010]扑克牌( 二分答案 )

二分答案.. 一开始二分的初始右边界太小了然后WA,最后一气之下把它改成了INF... ------------------------------------------------------------------------ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define rep( i , n ) for( int i = 0 ; i

【bzoj2280】[Poi2011]Plot 二分+倍增+二分+最小圆覆盖

题目描述 给出一系列点p_1, p_2, ... , p_n,将其分成不多余m个连续的段,第i段内求一个点q_i,使得q_i到这段内点的距离的最大值的最大值最小 输入 第一行,n m下面n行,每行两个整数,表示p_i的x y坐标1<=m<=n<=100000坐标范围[-1000000,1000000] 0<p,q,r<=150,输入中至少包含一个’N’ 输出 第一行,q_i到这段内点的距离的最大值的最大值的最小值第二行,分成的段数k下面k行,每行两个实数,表示q_k的x y坐

BZOJ 4077 Wf2014 Messenger 二分答案+计算几何

题目大意:给定两条折线,Alice沿着第一条折线走,Bob沿着第二条折线走,邮递员从Alice路径上的任意一点出发,沿直线走到Bob的路径上后刚好和Bob相遇,三人的速度都是1m/s,求邮递员走的最短距离,无解输出impossible 二分答案,然后让Bob提前出发mid,然后求出Alice和Bob全程的最短距离,判断是否≤mid就行了 无解比较难办,反正我是提前判断了无解的情况 #include <cmath> #include <cstdio> #include <cst