HDU 3932 Groundhog Build Home (模拟退火算法)
来源:互联网 发布:红色高棉 知乎 编辑:程序博客网 时间:2024/06/05 02:31
题意:找出一个点使得这个点到n个点的最长距离最短。
分析:模拟退火算法。
#include <iostream>#include<cstdio>#include<ctime>#include<cmath>#include<algorithm>#include<cstdlib>using namespace std;#define N 1005#define NUM 20#define D 50#define EPS 1e-3double a[N],b[N];int mo[8][2]={1,0,0,1,-1,0,0,-1,1,-1,-1,1,-1,-1,1,1};int main(){ int x,y,m; srand((unsigned int)time(NULL)); while(~scanf("%d%d%d",&x,&y,&m)) { for(int i=0;i<m;i++) { scanf("%lf%lf",&a[i],&b[i]); } double T=sqrt((double)x*x+y*y)+10; double ansx=(double)(rand()%1000+1)/1000.000*x; double ansy=(double)(rand()%1000+1)/1000.000*y; double ansdis=0; for(int i=0;i<m;i++) { ansdis=max(ansdis,sqrt((ansx-a[i])*(ansx-a[i])+(ansy-b[i])*(ansy-b[i]))); } while(T>EPS) { for(int k=0;k<D;k++){ for(int j=0;j<8;j++){ double tempx=ansx+(double)(rand()%1000+1)/1000.000*T*mo[j][0]; double tempy=ansy+(double)(rand()%1000+1)/1000.000*T*mo[j][1]; if(tempx<0||tempx>x||tempy<0||tempy>y) continue; double tempdis=0; for(int i=0;i<m;i++) { tempdis=max(tempdis,sqrt((tempx-a[i])*(tempx-a[i])+(tempy-b[i])*(tempy-b[i]))); } if(tempdis<ansdis) { ansx=tempx; ansy=tempy; ansdis=tempdis; } } } T=T*0.9; } printf("(%.1f,%.1f).\n%.1f\n",ansx,ansy,ansdis); } return 0;}
0 0
- HDU 3932 Groundhog Build Home (模拟退火算法)
- 多校第十场HRBEU &&hdu 3932 Groundhog Build Home(模拟退火算法)
- hdu 3932 Groundhog Build Home
- hdu 3932 Groundhog Build Home
- hdu 3932 Groundhog Build Home
- hdu 3932 Groundhog Build Home
- hdu 3932 Groundhog Build Home
- hdu 3932 Groundhog Build Home (最小圆覆盖)
- POJ 3932 Groundhog Build Home(最小圆覆盖)
- HDU 5017 Ellipsoid(模拟退火算法)
- hdu 5017 模拟退火算法
- HDU 5017 模拟退火算法
- hdu 1109 Run Away(模拟退火算法)
- hdu 5017(模拟退火)
- hdu 5017 Ellipsoid 模拟退火算法模板
- HDU 1109 Run Away 模拟退火算法
- 【HDU 1109 Run Away 模拟退火算法】
- 模拟退火算法(转载)
- 搁置已久的XD_JWXT的wp
- margin:0 auto无效原因
- SPOJ QTREE4Query on a tree IV
- 添加环境变量
- 什么是类?什么是对象?类和对象有什么关系?
- HDU 3932 Groundhog Build Home (模拟退火算法)
- spring MVC权限分配的实现
- ko驱动模块rmmod 后insmod 异常问题解决
- opencv图像写入视频详解
- jQuery使用ajaxSubmit()提交表单以及AjaxSubmit的一些用法
- struts2 配置文件的跳转总结
- 洛谷P1428 树状数组。。。
- 15.4.3 用于Generator的泛型方法
- Java在eclipse中调用opencv时报错:java.lang.UnsatisfiedLinkError的解决方法