POJ 1379 模拟退火
模拟退火算法,很久之前就写过一篇文章了。双倍经验题(POJ 2420)
题意:
在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大。
这个题意,很像二分定义,但是毫无思路,也不能暴力枚举,那就模拟退火。
参考著名的ACdream,哈哈,有个共同点,那就是,大部分的代码,都没有做接受准则,这也许是acmer对智能算法的不习惯吧~~~
#include <stdio.h>
#include <math.h>
#include <algorithm> using namespace std; const int maxn = ; int X,Y,M;
int Kase; struct Node {
double x,y;
}nodes[maxn]; int dx[] = {,,-,};
int dy[] = {-,,,}; double dist(Node a,Node b) {
return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} double calc(Node p) {
double ret = 0x3f3f3f3f;
for(int i = ; i < M; i++)
ret = min(ret,dist(p,nodes[i]));
return ret;
} int main()
{
//freopen("in.txt","r",stdin);
scanf("%d",&Kase);
while(Kase--) {
scanf("%d%d%d",&X,&Y,&M); for(int i = ; i < M; i++) scanf("%lf%lf",&nodes[i].x,&nodes[i].y); Node s;
s.x = X/;
s.y = Y/; double t = max(X,Y);
double ansx = X/;
double ansy = Y/;
double ans = calc(s); Node tmp;
tmp.x = ;
tmp.y = ;
double anstmp = calc(tmp);
if(anstmp>ans) {
ans = anstmp;
ansx = ;
ansy = ;
} tmp.x = ;
tmp.y = Y;
anstmp = calc(tmp);
if(anstmp>ans) {
ans = anstmp;
ansx = ;
ansy = Y;
} tmp.x = X;
tmp.y = ;
anstmp = calc(tmp);
if(anstmp>ans) {
ans = anstmp;
ansx = X;
ansy = ;
} tmp.x = X;
tmp.y = Y;
anstmp = calc(tmp);
if(anstmp>ans) {
ans = anstmp;
ansx = X;
ansy = Y;
} while(t>1e-) {
bool flag = true;
while(flag) {
flag = false;
for(int i = ; i < ; i++) {
Node v;
v.x = s.x + dx[i]*t;
v.y = s.y + dy[i]*t;
if(v.x>X||v.y>Y||v.x<||v.y<) continue; double tp = calc(v); if(tp>ans) {
ans = tp;
flag = true;
ansx = v.x;
ansy = v.y;
s = v;
}
}
}
t = t*0.98;
} printf("The safest point is (%.1f, %.1f).\n",ansx,ansy);
}
return ;
}
POJ 1379 模拟退火的更多相关文章
- POJ 1379 Run Away 【基础模拟退火】
题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...
- POJ.1379.Run Away(模拟退火)
题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...
- POJ 1379 (随机算法)模拟退火
题目大意: 给定一堆点,找到一个点的位置使这个点到所有点中的最小距离最大 这里数据范围很小,精度要求也不高,我们这里可以利用模拟退火的方法,随机找到下一个点,如果下一个点比当前点优秀就更新当前点 参考 ...
- poj 1379 Run Away 模拟退火 难度:1
Run Away Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6482 Accepted: 1993 Descript ...
- poj 2420(模拟退火)
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6066 Accepted: 285 ...
- POJ 1379
模拟退火算法. 随机MAX个点,然后,退火移动,选取距离所有点中最短中最长者即可.理解和我上一篇一样. #include <iostream> #include <cstdio> ...
- BZOJ 1379 模拟退火
模拟退火的第一题~ //By SiriusRen #include <cmath> #include <cstdio> #include <algorithm> u ...
- POJ 1379 Run Away
题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交 ...
- POJ 2069 模拟退火算法
Super Star Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6422 Accepted: 1591 Spec ...
随机推荐
- zabbix_agent 主动模式配置
一,主动与被动模式 默认的模式就是被动模式由服务端发送执行指令,客户端再执行 主动模式则为客户机自己找服务器拿任务执行 二,主动模式配置 查看客户端配置文件 grep '^[a-Z]' /etc/za ...
- Apache Beam的目标
不多说,直接上干货! Apache Beam的目标 统一(UNIFIED) 基于单一的编程模型,能够实现批处理(Batch processing).流处理(Streaming Processing), ...
- Android RelativeLayout 属性 转自互联网
// 相对于给定ID控件 android:layout_above 将该控件的底部置于给定ID的控件之上; android:layout_below 将该控件的底部置于给定ID的控件之下; andro ...
- TOJ 4523 Transportation
Description Given N stations, you want to carry goods from station 1 to station N. Among these stati ...
- 腾讯蔡晨:十年沉淀,腾讯iOA为企业安全保驾护航
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 背景:5月23-24日,以"焕启"为主题的腾讯"云+未来"峰会再广州召开,广东省各级政府机构领导.海 ...
- 【坑】自动化测试之Excel表格
参考一位大神的博客项目架构,把元素和数据都参数化,但是总是被excel表格坑 1.无法下拉 动作列通过下拉列表来控制,点击下拉列表无反应 解决方案:不知道是不是中间动了什么,因为Excel版本的问题, ...
- 【linux相识相知】独立硬盘冗余阵列-RAID
独立硬盘冗余阵列(RAID,Redundant Array of Independant Disks),旧称为廉价磁盘冗余阵列(Redundant Array of Inexpensive Disks ...
- union、except和intersect查询
1. union联合查询 (合并) select r.room_id from room r union select rp.num from room_type rp 要求表1和表2的查询结果结构 ...
- The Dangers of the Large Object Heap(转载,LOH内存碎片情景重现)
原文地址:https://www.simple-talk.com/dotnet/.net-framework/the-dangers-of-the-large-object-heap/ You'd h ...
- Zepto和Jquery区别
---恢复内容开始--- <zepto移动端事件> 1.$("#xx").tap(function(){ //tap在屏幕点击时触发 alert("sssss ...