BZOJ 2823 AHOI2012 信号塔 计算几何

2023-11-03 09:10

本文主要是介绍BZOJ 2823 AHOI2012 信号塔 计算几何,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目大意:给定n个点(n<=50W),求最小圆覆盖

逗我?n<=50W?最小圆覆盖?O(n^3)?

其实数据是随机生成的 经过验证 随机生成50w的点集 平均在凸包上的点在50~60个左右

于是求凸包之后就可以随便乱搞了- - 不会写O(n^3)的最小圆覆盖 写了O(n^4)的照过

注意最小圆覆盖时要讨论有两点在圆上和有三点在圆上两种情况

--------------------以上是题解-----------以下是粗口---------------------

出题人我*你*!!数据随机生成的就不能【哔】一声么!!本大爷刷这题卡了5个小时啊啊啊!

刚开始觉得做不了写了模拟退火有木有啊!!WA成狗啊有木有!!!

还有TM那坑B的样例是怎么个鬼!

void Sample_Explanation(bool f**k)

{

最后求得的圆是由第一个点和第三个点所构成的线段作为直径的圆

其中第五个点虽然怎么看怎么在圆上 但是这个点实际上是在圆内

如果求得答案为(2.49,2.86),并不是被卡精度了,而是找到了由第1、3、5三个点构成的圆

显然这个圆并不是最优解

参考图片:

}

#include <cmath>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 500500
#define INF 1e20
#define EPS 1e-7
using namespace std;
struct point{double x,y;point(){}point(double _,double __):x(_),y(__) {}void Read(){x=rand();y=rand();}bool operator < (const point &p) const{if(fabs(x-p.x)>1e-7)return x < p.x;return y < p.y;}
}points[M],ans;
int n;
double ans_distance=INF;
point *stack[M];int top;
point *on_the_hull[M];int cnt;
double Rand()
{return rand()%10000/10000.0;
}
double Distance(const point &p1,const point &p2)
{double dx=p1.x-p2.x;double dy=p1.y-p2.y;return sqrt(dx*dx+dy*dy);
}
double Get_Slope(const point &p1,const point &p2)
{if(fabs(p1.x-p2.x)<EPS)return p1.y<p2.y?INF:-INF;return (p1.y-p2.y)/(p1.x-p2.x);
}
void Get_Convex_Hull()
{int i;sort(points+1,points+n+1);for(i=1;i<=n;i++){while(top>=2&&Get_Slope(*stack[top-1],*stack[top])<Get_Slope(*stack[top],points[i])+EPS)stack[top--]=0x0;stack[++top]=&points[i];}while(top)on_the_hull[++cnt]=stack[top],stack[top--]=0;for(i=1;i<=n;i++){while(top>=2&&Get_Slope(*stack[top-1],*stack[top])>Get_Slope(*stack[top],points[i])-EPS)stack[top--]=0x0;stack[++top]=&points[i];}for(top--;top>1;top--)on_the_hull[++cnt]=stack[top];
}
point Get_Centre(const point &a,const point &b,const point &c)
{long double a1=a.x-b.x,b1=a.y-b.y,c1=0.5*( (a.x*a.x-b.x*b.x) + (a.y*a.y-b.y*b.y) );long double a2=a.x-c.x,b2=a.y-c.y,c2=0.5*( (a.x*a.x-c.x*c.x) + (a.y*a.y-c.y*c.y) );return point( (c2*b1-c1*b2)/(a2*b1-a1*b2) , (a2*c1-a1*c2)/(a2*b1-a1*b2) );
}
void Judge(const point &p)
{int i;double max_distance=0;for(i=1;i<=cnt;i++)	{max_distance=max(max_distance,Distance(p,*on_the_hull[i]) );if(max_distance>ans_distance)return ;}ans=p;ans_distance=max_distance;
}
int main()
{srand((unsigned)time(0x0));int i,j,k;cin>>n;for(int T=1000;T;T--){top=0;cnt=0;for(i=1;i<=n;i++)points[i].Read();Get_Convex_Hull();cout<<cnt<<endl;}
}

·

这篇关于BZOJ 2823 AHOI2012 信号塔 计算几何的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/337143

相关文章

uva 10387 Billiard(简单几何)

题意是一个球从矩形的中点出发,告诉你小球与矩形两条边的碰撞次数与小球回到原点的时间,求小球出发时的角度和小球的速度。 简单的几何问题,小球每与竖边碰撞一次,向右扩展一个相同的矩形;每与横边碰撞一次,向上扩展一个相同的矩形。 可以发现,扩展矩形的路径和在当前矩形中的每一段路径相同,当小球回到出发点时,一条直线的路径刚好经过最后一个扩展矩形的中心点。 最后扩展的路径和横边竖边恰好组成一个直

poj 1113 凸包+简单几何计算

题意: 给N个平面上的点,现在要在离点外L米处建城墙,使得城墙把所有点都包含进去且城墙的长度最短。 解析: 韬哥出的某次训练赛上A出的第一道计算几何,算是大水题吧。 用convexhull算法把凸包求出来,然后加加减减就A了。 计算见下图: 好久没玩画图了啊好开心。 代码: #include <iostream>#include <cstdio>#inclu

uva 1342 欧拉定理(计算几何模板)

题意: 给几个点,把这几个点用直线连起来,求这些直线把平面分成了几个。 解析: 欧拉定理: 顶点数 + 面数 - 边数= 2。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#inc

uva 11178 计算集合模板题

题意: 求三角形行三个角三等分点射线交出的内三角形坐标。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <

XTU 1237 计算几何

题面: Magic Triangle Problem Description: Huangriq is a respectful acmer in ACM team of XTU because he brought the best place in regional contest in history of XTU. Huangriq works in a big compa

poj 3304 几何

题目大意:给出n条线段两个端点的坐标,问所有线段投影到一条直线上,如果这些所有投影至少相交于一点就输出Yes!,否则输出No!。 解题思路:如果存在这样的直线,过投影相交点(或投影相交区域中的点)作直线的垂线,该垂线(也是直线)必定与每条线段相交,问题转化为问是否存在一条直线和所有线段相交。 若存在一条直线与所有线段相交,此时该直线必定经过这些线段的某两个端点,所以枚举任意两个端点即可。

POJ 2318 几何 POJ 2398

给出0 , 1 , 2 ... n 个盒子, 和m个点, 统计每个盒子里面的点的个数。 const double eps = 1e-10 ;double add(double x , double y){if(fabs(x+y) < eps*(fabs(x) + fabs(y))) return 0 ;return x + y ;}struct Point{double x , y

poj 2653 几何

按顺序给一系列的线段,问最终哪些线段处在顶端(俯视图是完整的)。 const double eps = 1e-10 ;double add(double x , double y){if(fabs(x+y) < eps*(fabs(x) + fabs(y))) return 0 ;return x + y ;}struct Point{double x , y ;Point(){}Po

音视频入门基础:WAV专题(10)——FFmpeg源码中计算WAV音频文件每个packet的pts、dts的实现

一、引言 从文章《音视频入门基础:WAV专题(6)——通过FFprobe显示WAV音频文件每个数据包的信息》中我们可以知道,通过FFprobe命令可以打印WAV音频文件每个packet(也称为数据包或多媒体包)的信息,这些信息包含该packet的pts、dts: 打印出来的“pts”实际是AVPacket结构体中的成员变量pts,是以AVStream->time_base为单位的显

计算数组的斜率,偏移,R2

模拟Excel中的R2的计算。         public bool fnCheckRear_R2(List<double[]> lRear, int iMinRear, int iMaxRear, ref double dR2)         {             bool bResult = true;             int n = 0;             dou