HDU 1109
http://acm.hdu.edu.cn/showproblem.php?pid=1109
一个范围内给一堆点,求到这些点的最短距离最大
模拟退火,温度是步长
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <ctime>
#include <cmath>
using namespace std ;
const double eps=1e- ;
int X,Y,M ; struct point
{
double x,y ;
int OK()
{
if(x>-eps && x<X+eps && y>-eps && y<Y+eps)return ;
return ;
}
}p[],r[] ; double dis(point a,point b)
{
return sqrt(pow(a.x-b.x,)+pow(b.y-a.y,)) ;
} double ans[] ; int main()
{
int T ;
scanf("%d",&T) ;
srand(time(NULL)) ;
while(T--)
{
scanf("%d%d%d",&X,&Y,&M) ;
for(int i= ;i<M ;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y) ;
}
for(int i= ;i< ;i++)
{
r[i].x=(rand()%+)/1000.0*X ;
r[i].y=(rand()%+)/1000.0*Y ;
ans[i]=1e18 ;
for(int j= ;j<M ;j++)
{
ans[i]=min(ans[i],dis(p[j],r[i])) ;
}
}
double tmp=max(X,Y) ;
while(tmp>0.01)
{
for(int i= ;i< ;i++)
{
point now=r[i],next ;
for(int j= ;j< ;j++)
{
double rad=(rand()%+)/1000.0**3.1415926535 ;
next.x=now.x+cos(rad)*tmp ;
next.y=now.y+sin(rad)*tmp ;
if(!next.OK())continue ;
double m=1e18 ;
for(int k= ;k<M ;k++)
m=min(m,dis(p[k],next)) ;
if(m>ans[i])
{
ans[i]=m ;
r[i]=next ;
}
}
}
tmp*=0.8 ;
}
double res=0.0 ;
int idx ;
for(int i= ;i< ;i++)
{
if(ans[i]>res)
{
res=ans[i] ;
idx=i ;
}
}
printf("The safest point is (%.1lf, %.1lf).\n",r[idx].x,r[idx].y) ;
}
return ;
}
HDU 1109的更多相关文章
- HDU 1109 Run Away
题目大意:给一个矩阵的长宽,再给n个点,求矩阵区域内某个点到各个点的最小距离的最大值,输出所求点的坐标 这道题我还是写了随机化乱搞,不过由于比较懒于是就没有写模拟退火,不过也是可以AC的 我们先初始随 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- centos彻底删除文件夹、文件命令
[1]新建文件夹 格式:mkdir 文件名 view source1 mkdir /home/test 新建一个名为test的文件夹在home下 [2]新建文本 vi /home/test.s ...
- MATLAB 矩阵转化为灰度图
A=[ 1.00 0.96 0.98 0.88 0.94 0.61 0.96 0.80 0.98 0.89 0.96 1.00 0.94 0.90 0.95 0.71 0.96 0.83 0.90 0 ...
- 函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。
在dllimport中加入CallingConvention参数就行了,[DllImport(PCAP_DLL, CharSet = CharSet.Auto, CallingConvention = ...
- 使用Obsolete特性来标记方法过时或弃用
我们在维护一些老的系统的时候,经常会遇到某个方法不再使用的情况,我们又不能直接将其删除,因为系统中可能还有很多地方有引用它,所以比较安全保险的做法是,使用Obsolete特性来标记它过时或弃用.如下代 ...
- 如何在 Arch Linux 中安装 DNSCrypt 和 Unbound
DNSCrypt 是一个用于对 DNS 客户端和 DNS 解析器之间通信进行加密和验证的协议.它可以阻止 DNS 欺骗或中间人攻击. DNSCrypt 可用于大多数的操作系统,包括 Linux,Win ...
- mouseleave 与 mouseout 的不同
Q:给某div添加mouseout事件后,在空白区域移动到其子元素(如按钮)上(此时并没有离开此div)时,会触发mouseout事件,而mouseleave则不会 A:与 mouseout 事件不同 ...
- vsftp 配置
安装和基本配置网上很多文章,但他们的最终效果不是我想要的: 我想要的是,ftp上传的文件用户可以通过apache的http服务访问,也就是ftp上传的文件可以通过浏览器访问,并且可以通过ftp客户端修 ...
- C++-不要在构造和析构函数中调用虚函数
在实习的单位搞CxImage库时不知为什么在Debug时没有问题,但是Release版里竟然跳出个Pure virtual function call error! 啥东西呀,竟然遇上了,就探个究竟吧 ...
- 如何在windows上搭建ftp服务器
FTP(File Transfer Protocol)是TCP/IP网络上两台计算机传送文件的协议,使得主机间可以共享文件.目前有很多软件都能实现这一功能,然而windows自带的IIS就可以帮助你搭 ...
- JAVA之关于super的用法
JAVA之关于super的用法 路漫漫其修远兮,吾将上下而求索.——屈原<离骚> 昨天写this用法总结的时候,突然产生了一个问题,请教别人之后,有了自己的一点认识.还是把它写下来,为 ...