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的更多相关文章

  1. HDU 1109 Run Away

    题目大意:给一个矩阵的长宽,再给n个点,求矩阵区域内某个点到各个点的最小距离的最大值,输出所求点的坐标 这道题我还是写了随机化乱搞,不过由于比较懒于是就没有写模拟退火,不过也是可以AC的 我们先初始随 ...

  2. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  3. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. 超棒的响应式设计测试书签和工具(bookmarks)(转)

    一.测试书签(bookmarks) Viewport Resizer 这个书签号称拥有158个国家3万多活跃的用户,主要特性: 完全自定制 方便的添加自定义尺寸 手动的横竖屏切换 自动的横竖屏切换 ( ...

  2. splunk 索引过程

    术语: Event :Events are records of activity in log files, stored in Splunk indexes. 简单说,处理的日志或话单中中一行记录 ...

  3. 关于PATH_INFO SCRIPT_NAME SCRIPT_FILENAME REDIRECT_URL 详解

    参考:http://www.nginx.cn/426.html  http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/09/13/217507 ...

  4. noip知识点总结之--线性筛法及其拓展

    一.线性筛法 众所周知...线性筛就是在O(n)的时间里找出所有素数的方法 code: void get_prime(int N){ int i, j, k; memset(Flag, ); ; i ...

  5. PHP中的include、include_once、require、require_once

    include.include_once().require.require_once() 作用: 通过 include 或 require 语句,可以将 PHP 文件的内容插入另一个 PHP 文件( ...

  6. redhat enterprixe 5.0 NFS服务配置与管理

    一.了解NFS Samba 是主要用于实现Linux和Windows操作系统之间文件共享的协议,而NFS则是实现UNIX和Linux操作系统之间文件共享的协议. NFS可以把网络上远程的文件挂载到本机 ...

  7. Android利用ContentProviderOperation添加联系人

    Android添加联系人有两种方式: 1. 直接调用插入语句,先插入一个空Item,得到一个id,然后给这个id对应的插入其他信息,如姓名,号码,邮件等: 2. 利用ContentProviderOp ...

  8. cmd命令行中的errorlevel和延迟赋值

    最近用到了命令行,一点心得: 1.errorlevel返回的确实是上一条命令的返回值,但不同命令的表现完全不同.比如: dir echo %errorlevel% //显示0 dir aldkalf ...

  9. AIX查看内存卡槽

    1.lscfg -vp|grep Processor 2.lscfg -vp|grep -p Memory

  10. Listview之优化BaseAdapter中的getView中的contentView

    BaseAdapter中getView中改动的地方: @Override public View getView(int position, View contentView, ViewGroup a ...