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 ...
随机推荐
- Java 之 I/O 系列 02 ——序列化(二)
Java 之 I/O 系列 目录 Java 之 I/O 系列 01 ——基础 Java 之 I/O 系列 02 ——序列化(一) Java 之 I/O 系列 02 ——序列化(二) 继续上篇的第二个问 ...
- OUT函数及其熟练使用,split的用法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- vue.js——初体验
看到最近很火的vue.js,于是开启了自己人生中首篇翻译之路,才意识到这个纯英文版的的确没有中文的通俗易懂~~~~~~不过, 还是硬着头皮把这篇英文版的博客给翻译完了,希望可以帮助自己的同时也方便别人 ...
- python的一点小常识
在Python中,有两种变长参数,分别是元组(非关键字参数)和字典(关键字参数),其参数以一个*开头表示任意长度的元组[tuple],可以接收连续一串参数,参数以两个*开头表示一个字典[dict],即 ...
- 【北京站】详解Visual Studio 2013:开发iOS及android应用!现场图集
现场图集: 活动介绍地址:http://huiyi.csdn.net/module/meeting/meeting/info/660/biz
- dll和ocx比较
ActiveX,OLE是基于COM的一种应用,其文件后缀一般以dll和ocx结尾:ocx作为一种特殊的dll文件,具有一定的用户界面和事件响应,而dll文件只是方法和属性的集合. 一.关于DLL的介绍 ...
- POJ 1094 拓扑排序
Description: 规定对于一个只有大写字母的字符串是有大小顺序的.如ABCD.即A<B.B<C.C<D.那么问题来了.现在第一行给你n, m代表序列里只会出现前n的 ...
- 克隆机器后eth1变为eth0问题
1. 清空该文件 2.进入网络配置文件把HADDR 和UUID注释掉,并重启 3.成功修改eth0 4. 4.可以结合这篇帖子来看 http://www.cnblogs.com/zydev/p/4 ...
- Visual Studio 2012中的为创建类时的添加注释模板
我们往往需要给类添加注释,我们可以把注释块复制出来,放到文件中,然后在需要的时候,复制.粘贴.这样的重复劳动增加了程序员的体力劳动,而VS中给我们提供了项模版,我们只需要在其中修改一点点模版就能达到这 ...
- 如何在 CentOS 中设置 NTP 服务器
网络时间协议(NTP)用来同步网络上不同主机的系统时间.你管理的所有主机都可以和一个指定的被称为 NTP 服务器的时间服务器同步它们的时间.而另一方面,一个 NTP 服务器会将它的时间和任意公共 NT ...