[几何 模拟退火 || 随机增量法] Codeforces 442E #253 (Div. 1) E. Gena and Second Distance
来源:互联网 发布:项目管理方法论 知乎 编辑:程序博客网 时间:2024/06/05 00:33
怎么都在理性愉悦啊 总算做到一道有点思路的题了
官方题解
题解里说的是什么呢
我们先二分答案
然后我们考虑
我们肯定可以挪动这个圆 使得有至少一个点在边界上
枚举点
实际上就是C的圆周上的不被两个以上以其他点为圆心相同半径的圆覆盖的点
这个可以极角排序一发
这样我们的复杂度就是
然后我们采用随机的思想 我们把点random_shuffle一下
一个一个点去做 把二分的过程套在里面 如果当前点在已知
这样 我们可以证明期望做
证明很轻易啊 因为点shuffle后 每个点答案相当于随机序列 递增子序列的长度是
说了这么多 但是我懒 写了个模拟退火 嘿嘿嘿
#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<ctime>using namespace std;typedef double ld;inline ld sqr(ld x) { return x*x; }struct PP{ ld x,y; PP(ld x=0,ld y=0):x(x),y(y){ } friend PP operator +(PP a,PP b) { return PP(a.x+b.x,a.y+b.y); } friend PP operator -(PP a,PP b) { return PP(a.x-b.x,a.y-b.y); } friend PP operator *(PP a,ld b) { return PP(a.x*b,a.y*b); } friend PP operator /(PP a,ld b) { return PP(a.x/b,a.y/b); } friend ld det(PP a,PP b) { return a.x*b.y-a.y*b.x; } friend ld operator *(PP a,PP b) { return a.x*b.x+a.y*b.y; } friend ld dist(PP a,PP b){ return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); } void read(){ double _x,_y; scanf("%lf%lf",&_x,&_y); x=_x; y=_y; }};const int N=2005;int n,w,h;PP p[N]; double Ans=0;inline ld F(PP a){ double min1=1e30,min2=1e30,d; for (int i=1;i<=n;i++){ d=dist(a,p[i]); if (d<min1){ min2=min1,min1=d; }else min2=min(min2,d); } if (min2>Ans) Ans=max(Ans,min2); return min2;}inline bool jud(PP p){ return p.x>=0 && p.x<=w && p.y>=0 && p.y<=h;}const double PI=acos(-1.0);inline void SA(){ PP a=PP((rand()%1000)/1000.0*(double)w,(rand()%1000)/1000.0*(double)h),b; double ans=F(a),cur,delta; for (double T=sqrt((double)w*w+(double)h*h);T>1e-15;T*=.995){ double ang=rand()%100/100.0*2*PI; b=a+PP(cos(ang)*T,sin(ang)*T); if (!jud(b)) continue; cur=F(b); delta=cur-ans; if (delta>0) a=b,ans=cur; }}int main(){ srand(time(0)); freopen("t.in","r",stdin); freopen("t.out","w",stdout); scanf("%d%d%d",&w,&h,&n); for (int i=1;i<=n;i++) p[i].read(); const int Case=10; for (int i=1;i<=Case;i++) SA(); printf("%.15lf\n",Ans); return 0;}
0 0
- [几何 模拟退火 || 随机增量法] Codeforces 442E #253 (Div. 1) E. Gena and Second Distance
- 【模拟退火】最小球POJ 2069/codeforces 82 E
- Codeforces Round #204 (Div. 1) E. Jeff and Permutation
- Codeforces Round #129 (Div. 1)E. Little Elephant and Strings
- Codeforces #276 div.1 E
- [欧拉回路] Codeforces 429E #245 (Div. 1) E. Points and Segments
- Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟
- Codeforces Round #357 (Div. 2) E 计算几何
- Codeforces #284 (Div.1 A~E & Div.2 A~E)
- Codeforces Round #192 (Div. 2) E. Graph Reconstruction (随机算法)
- CodeForces 682 E.Alyona and Triangles(计算几何)
- Codeforces Problemset 30E(#30 div.1 E)
- Codeforces Problemset 10E(#10 div.1 E)
- Codeforces Problemset 198E(#125 div.1 E)
- [构造] Codeforces 736E #382 (Div. 1) E. Chess Championship
- Codeforces 682E 计算几何
- [Codeforces 897E. Willem, Chtholly and Seniorious]概率随机+set
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E
- Poj 2018 Best Cow Fences(分数规划+DP&&斜率优化)
- 关联规则挖掘
- Navicat for mysql 功能介绍
- SQL语句Alias
- 服务器管理-- tomcat
- [几何 模拟退火 || 随机增量法] Codeforces 442E #253 (Div. 1) E. Gena and Second Distance
- springmvc和json整合配置方法
- spring MVC中的controller是单例模式,但是是多线程,各个线程之间不影响!
- dubbo 并发控制 和 连接控制
- linux安装jdk
- MySQL创建用户并指定数据库权限
- 验证phone是否注册微信
- elasticsearch spring 集成
- Swagger简介