POJ 1379 Run Away(模拟退火)
来源:互联网 发布:单片机温度控制系统 编辑:程序博客网 时间:2024/06/14 04:15
题目链接:http://poj.org/problem?id=1379
这道题目应该算是真正意义上的模拟退火了,每一步基本上都是随机的
防止一个不准确,来30个,防止一个方向不行,随机来30个方向,取结果
最好的一个方向!
#include <string.h>#include <stdio.h>#include <algorithm>#include <iostream>#include <ctime>#include <stdlib.h>#include <cmath>#define maxn 1010#define MIN(a,b) (a<b?a:b)#define MAX(a,b) (a>b?a:b)#define inf 1e12#define eps 1e-8const double PI=acos(-1.0);using namespace std;struct point{ double x,y;}po[maxn],ans_po[100];int X,Y,n;double ans[100];double dis(point &a,point &b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double find_max(point &a){ double ans=inf,t; for(int i=0;i<n;i++){ t=dis(a,po[i]); ans=MIN(t,ans); } return ans;}int main(){ int i,j,k,t; scanf("%d",&t); double step,theta,now; point temp; srand(unsigned(time(NULL))); while(t--){ scanf("%d%d%d",&X,&Y,&n); for(i=0;i<n;i++) scanf("%lf%lf",&po[i].x,&po[i].y); for(i=0;i<30;i++){ ans_po[i].x=(rand()%1001)/1000.0*X; ans_po[i].y=(rand()%1001)/1000.0*Y; ans[i]=find_max(ans_po[i]); } step=MAX(X,Y); while(step>eps){ for(i=0;i<30;i++){ theta=(rand()%1001)/500.00*PI; for(j=0;j<30;j++){ temp.x=ans_po[j].x+cos(theta)*step; temp.y=ans_po[j].y+sin(theta)*step; if(temp.x>X || temp.x<0 || temp.y>Y || temp.y<0) continue; now=find_max(temp); if(now>ans[j])ans[j]=now,ans_po[j]=temp; } } step*=0.8; } j=0,now=ans[0]; for(i=1;i<30;i++) if(ans[i]>now) now=ans[i],j=i; printf("The safest point is (%.1lf, %.1lf).\n",ans_po[j].x,ans_po[j].y); } return 0;}
- poj 1379 Run Away(模拟退火)
- POJ 1379 Run Away(模拟退火)
- POJ--1379[Run Away] 模拟退火
- 【POJ 1379 Run Away模拟退火】
- poj 1379 Run away 模拟退火
- POJ 1379 Run Away(基础模拟退火)
- [poj 1379]Run Away[模拟退火]
- poj 1379 Run Away 模拟退火
- POJ 1379 Run Away 模拟退火
- POJ 1379 run away 模拟退火算法
- POJ, 1379Run Away(模拟退火算法)
- poj 1379 Run Away 计算几何 模拟退火
- [模拟退火 || Voronoi图] POJ 1379 Run Away
- 模拟退火算法(run away poj1379)
- 【模拟退火】 poj1379 Run Away
- 【POJ1379】Run Away 模拟退火
- 模拟退火 hdu1109 Run away
- POJ 1379 Run away & POJ 2420 A star not a Tree [模拟退火] [爬山算法]
- spring中commons-logging.jar的作用
- POJ 3067 —— 树状数组求逆序对
- java对象的创建过程
- jquery checkbox全选与全不选
- 设计模式之工厂模式
- POJ 1379 Run Away(模拟退火)
- 在Linux下使用vim配合xxd查看并编辑二进制文件
- 2014年Baidu的Interview Question(02)【转载】
- 常见面试题汇总
- [Accessibility] Missing contentDescription attribute on image
- request 获取各项参数以及意义
- Android开发优化之——对Bitmap的内存优化
- Android开发优化之——使用软引用和弱引用
- java术语{PO/POJO/VO/BO/DAO/DTO}