BZOJ 1379 模拟退火
模拟退火的第一题~
//By SiriusRen
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int cases,X,Y,M;
struct Point{double x,y,dis;}point[1005],b[33],ans,t;
double dis(Point a){
double tmp=1e8;
for(int i=1;i<=M;i++){
double tx=a.x-point[i].x,ty=a.y-point[i].y;
tmp=min(tmp,sqrt(tx*tx+ty*ty));
}return tmp;
}
int main(){
srand(1005730820),scanf("%d",&cases);
while(cases--){
scanf("%d%d%d",&X,&Y,&M),ans.dis=0;
for(int i=1;i<=M;i++)scanf("%lf%lf",&point[i].x,&point[i].y);
for(int i=1;i<=30;i++)b[i].x=rand()%X+1,b[i].y=rand()%Y+1,b[i].dis=dis(b[i]);
for(double i=max(X,Y);i>=1e-3;i*=0.9)
for(int j=1;j<=30;j++)
for(int k=1;k<=30;k++){
double ran=rand();
t.x=b[j].x+cos(ran)*i,t.y=b[j].y+sin(ran)*i,t.dis=dis(t);
if(t.x<0||t.x>X||t.y<0||t.y>Y)continue;
if(t.dis>b[j].dis)b[j]=t;
}
for(int i=1;i<=30;i++)if(ans.dis<b[i].dis)ans=b[i];
printf("The safest point is (%.1f, %.1f).\n",ans.x,ans.y);
}
}
BZOJ 1379 模拟退火的更多相关文章
- POJ 1379 模拟退火
模拟退火算法,很久之前就写过一篇文章了.双倍经验题(POJ 2420) 题意: 在一个矩形区域内,求一个点的距离到所有点的距离最短的那个,最大. 这个题意,很像二分定义,但是毫无思路,也不能暴力枚举, ...
- BZOJ 3680 模拟退火
思路: 退火就好了-- 1.强烈建议题目名称改为"吊打出题人" 2.这种题放oj上啥心态...-–hzwer 二分TLE和WA 终于AC了-- //By SiriusRen #in ...
- 【BZOJ3680】吊打XXX(模拟退火)
[BZOJ3680]吊打XXX(模拟退火) 题面 BZOJ 题解 模拟退火... 就是模拟退火 然后这题有毒 各种调参数之后终于\(AC\)了.. 这种题就是玄学呀... 温度要调大 最后跑完还要向四 ...
- [BZOJ 3680] 吊打XXX 【模拟退火】
题目链接:BZOJ - 3680 题目分析 这道题是SLYZ的神犇把JSOI的平衡点那道题改了一下题面变成了吊打GTY神犇..Orz 第一次写模拟退火,只能照着别人的代码写,我看的是PoPoQQQ神犇 ...
- BZOJ 3680: 吊打XXX【模拟退火算法裸题学习,爬山算法学习】
3680: 吊打XXX Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 3192 Solved: 1198[Sub ...
- BZOJ 3680: 吊打XXX (模拟退火)
//yy:今天简单入门学了下ORZ 爬山算法:兔子朝着比现在高的地方跳去.它找到了不远处的最高山峰.但是这座山不一定是珠穆朗玛峰.这就是爬山算法,它不能保证局部最优值就是全局最优值. 模拟退火:兔子喝 ...
- bzoj 3680(洛谷1337) 吊打XXX——模拟退火
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3680 https://www.luogu.org/problemnew/show/P1337 ...
- 洛谷 P1337 平衡点 & bzoj 3680 吊打 XXX —— 模拟退火
题目:https://www.luogu.org/problemnew/show/P1337 https://www.lydsy.com/JudgeOnline/problem.php?id=3680 ...
- POJ 1379 Run Away 【基础模拟退火】
题意:找出一点,距离所有所有点的最短距离最大 二维平面内模拟退火即可,同样这题用最小圆覆盖也是可以的. Source Code: //#pragma comment(linker, "/ST ...
随机推荐
- [TypeScript] Generic Functions, class, Type Inference and Generics
Generic Fucntion: For example we have a set of data and an function: interface HasName { name: strin ...
- Restful技术
一.概述 Restful技术是一种架构风格(Representational State Transfer)表现层状态转化,而不是一种编程标准. 之前前后端混在一起,前端通过mapping映射找到后端 ...
- Codeforces Round #252 (Div. 2)-C,D
C题就是一个简单的模拟.首先给每一个人两个.然后把剩下的都给一个人就好了. 给的时候蛇形给. #include<stdio.h> #include<string.h> #inc ...
- org.hibernate.AssertionFailure: null id in com.you.model.User entry (don't flush the Session after a
1.错误描写叙述 org.hibernate.AssertionFailure: null id in com.you.model.User entry (don't flush the Sessio ...
- 实战c++中的vector系列--再谈vector的insert()方法(都是make_move_iterator惹的祸)
之前说过了关于vector的insert()方法,把vector B的元素插入到vector A中.vector A中的结果我们可想而知,可是vector B中的元素还会怎样? 看看之前写过的程序: ...
- Nashorn——在JDK 8中融合Java与JavaScript之力--转
原文地址:http://www.infoq.com/cn/articles/nashorn 从JDK 6开始,Java就已经捆绑了JavaScript引擎,该引擎基于Mozilla的Rhino.该特性 ...
- xshell同时发送多条命令
1.如图,勾选撰写栏 勾选全部会话 下面的是一个很方便的小技巧.分屏 如下图垂直排列 水平排列等等
- HDU 1233 还是畅通工程【最小生成树】
解题思路:kruskal算法:贪心选取最短的边构成一棵最小的生成树 共n个点,即先将所有的边排序,然后利用并查集判断,如果两点连通,则不加入树,不连通,则加入树,直到加入了n-1条边,构成生成树. 反 ...
- swift where 的作用
条件限定: 类型限定: 结构化查询模式. 用于结构体.记录字段.
- 洛谷P2607 [ZJOI2008]骑士 基环树动归
Code: #include<algorithm> #include<cstdio> #include<algorithm> #include<cstring ...