【BZOJ1844/2210】Pku1379 Run Away 模拟退火
【BZOJ1844/2210】Pku1379 Run Away
题意:矩形区域中有一堆点,求矩形中一个位置使得它到所有点的距离的最小值最大。
题解:模拟退火的裸题,再调调调调调参就行了~
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
const int maxn=1010;
struct pdd
{
double x,y;
pdd() {}
pdd(double a,double b) {x=a,y=b;}
}p[maxn];
int n;
double X,Y,T,mx;
pdd ans,now,neo;
double getdis(pdd a,pdd b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<'0'||gc>'9') {if(gc=='-')f=-f; gc=getchar();}
while(gc>='0'&&gc<='9') ret=ret*10+gc-'0',gc=getchar();
return ret*f;
}
double solve(pdd a)
{
double ret=1e10;
for(int i=1;i<=n;i++) ret=min(ret,getdis(a,p[i]));
if(ret>mx) mx=ret,ans=a;
return ret;
}
double Rand()
{
return rand()%1000/1000.0;
}
void work()
{
X=rd(),Y=rd(),n=rd();
int i,j;
for(i=1;i<=n;i++) p[i].x=rd(),p[i].y=rd();
mx=0;
for(j=1;j<=50;j++)
{
now.x=Rand()*X,now.y=Rand()*Y,solve(now),T=1000;
while(T>1e-3)
{
double a=2.0*acos(-1.0)*Rand();
neo.x=now.x+T*cos(a),neo.y=now.y+T*sin(a),T*=0.95;
if(neo.x<0||neo.x>X||neo.y<0||neo.y>Y) continue;
double de=solve(neo)-solve(now);
if(de>0) now=neo;
}
T=0.5;
for(i=1;i<=500;i++)
{
double a=2.0*acos(-1.0)*Rand();
neo.x=now.x+T*cos(a);
neo.y=now.y+T*sin(a);
if(neo.x<0||neo.x>X||neo.y<0||neo.y>Y) continue;
solve(neo);
}
}
printf("The safest point is (%.1lf, %.1lf).\n",ans.x,ans.y);
}
int main()
{
srand(2333666);
int T=rd();
while(T--) work();
}
【BZOJ1844/2210】Pku1379 Run Away 模拟退火的更多相关文章
- poj-1379 Run Away(模拟退火算法)
题目链接: Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 7982 Accepted: 2391 De ...
- Run Away 模拟退火
Run Away Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- PKU 1379 Run Away(模拟退火算法)
题目大意:原题链接 给出指定的区域,以及平面内的点集,求出一个该区域内一个点的坐标到点集中所有点的最小距离最大. 解题思路:一开始想到用随机化算法解决,但是不知道如何实现.最后看了题解才知道原来是要用 ...
- poj 1379 Run Away 模拟退火 难度:1
Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6482 Accepted: 1993 Descript ...
- POJ.1379.Run Away(模拟退火)
题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 一文搞懂GitLab安装部署及服务配置
GitLab安装部署 Git,GitHub,GitLab,这三个东东长得好像呀,都是个啥? Git是Linus Torvalds(如果不知道这位大神是谁,请出门左转,慢走不送~)为了帮助管理Linux ...
- POJ 1379 Run Away 【基础模拟退火】
题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...
- 模拟退火算法(run away poj1379)
http://poj.org/problem?id=1379 Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: ...
随机推荐
- UVa1476 Error Curves
画出函数图像后,发现是一个类似V字型的图. 可以用三分法找图像最低点 WA了一串,之后发现是读入优化迷之被卡. /*by SilverN*/ #include<iostream> #inc ...
- 以iphone6plus 为标准单位是px的页面 在运行时转换为rem
在页面中引入以下代码,把样式中带px单位的样式放到本页面中的<style>标签中 /** * Created by Administrator on 2017-03-14. */ /*** ...
- Xcode文件名后的字母含义
Xcode文件名后的字母含义 在Xcode中,左侧的dock区域显示项目结构.很多时候,文件名后方会出现一个字母提示,如M.A之类的.这实际是一种提示符号.如果项目中使用SVN.Git等版本控制工 ...
- 再次了解android中屏幕尺寸,单位等
android设备多种多样,要让你的app能够适配所有的屏幕是一件很痛苦的事情,在做适配之前我们首先需要了解android中dimension的定义 android中dimension是如何定义的? ...
- ios 使用keychain具体方法
Dictionary 写入: if ([self.currentUserAccount length] > 0) { Keycha ...
- ios7.1后setting中没有开启相机服务应用程序相机预览黑屏问题
if ( [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){ ...
- ios- nil NULL 和 NSNull
因为objective-c的集合对象,比如nsarray, nsdictionary, nsset等,都有可能包含nsnull对象,所以,如果以下代码中的item为nsnull,则会引起程序崩溃. N ...
- django忘记超级用户密码的解决方法
用Django shell: 1 python manage.py shell 然后获取你的用户名,并且重设密码: 1 2 3 4 from django.contrib.auth.models im ...
- MIDI制作的相关软件
Native Instruments Kontakt(音乐采样器) fl studio 12 v12.5.0.59 汉化版水果 http://xiazai.flstudiochina.com/wm ...
- 简单理解 ES7 Decorator(装饰器)
如何使用ES7 Decorator给你的游戏人物开挂? // 预告: 本文有点小难度,对js不太熟的人可能比较懵逼 // 本文的目的是让你们知其然 // ======================= ...