博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj1379 run away
阅读量:7033 次
发布时间:2019-06-28

本文共 2092 字,大约阅读时间需要 6 分钟。

题目大意:在矩形中找到一个点,使其跟最近的点距离最大

算法:模拟退火

 

模拟退火博大精深。。。

#include 
#include
#include
#include
#include
#include
#include
#define max( x , y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )#define min( x , y ) ( ( x ) < ( y ) ? ( x ) : ( y ) )#define FOR( TMP , ST , ED ) for ( int TMP = ( ST ) ; TMP < ( ED ) ; TMP ++ )#define RORD( TMP , ST , ED ) for ( int TMP = ( ST ) ; TMP > ( ED ) ; TMP ++ )const int max_int = ( 2147483467 ) , oo = ( 1e9 ) ;using namespace std ;const int maxn = ( 1e3 + 10 ) , Num = ( 30 ) ;int N , Kuan , Chang ;double X[ Num ] , Y[ Num ] , Dis[ Num ] , data[ maxn ][ 2 ] ;#define sqr( x ) ( ( x ) * ( x ) )inline double Get( double ST_x , double ST_y ){ double ans = ( double ) oo ; FOR ( i , 0 , N ) ans = min( ans , sqrt( sqr( ST_x - data[ i ][ 0 ] ) + sqr( ST_y - data[ i ][ 1 ] ) ) ) ; return ans ;}int main(){ freopen( "poj1379.in" , "r" , stdin ) , freopen( "poj1379.out" , "w" , stdout ) ; int Test ; srand( time( 0 ) ) ; for ( scanf( "%d" , &Test ) ; Test -- ; ) { cout << "The safest point is " ; scanf( "%d%d%d" , &Kuan , &Chang , &N ) ; FOR ( i , 0 , N ) scanf( "%lf%lf" , &data[ i ][ 0 ] , &data[ i ][ 1 ] ) ; FOR ( i , 0 , Num ) { X[ i ] = rand() % Kuan + 0.01 , Y[ i ] = rand() % Chang + 0.01 ; Dis[ i ] = Get( X[ i ] , Y[ i ] ) ; } double T = ( double ) max( Kuan , Chang ) / sqrt( ( double ) Num ) , Dec = 0.80 ; double eps = ( 1e-7 ) , Pi = asin( 1.0 ) * 2.0 ; for ( ; T >= eps ; T *= Dec ) FOR ( i , 0 , Num ) FOR ( j , 0 , Num ) { double xx , yy , New , Yzx = ( ( double ) rand() / 32768.0 ) * 2.0 * Pi ; xx = X[ i ] + cos( Yzx ) * T , yy = Y[ i ] + sin( Yzx ) * T ; New = Get( xx , yy ) ; if ( New > Dis[ i ] && xx >= 0 && xx <= Kuan && yy >= 0 && yy <= Chang ) Dis[ i ] = New , X[ i ] = xx , Y[ i ] = yy ; } double Ans = ( double ) - oo , xx , yy ; FOR ( i , 0 , Num ) if ( Ans < Dis[ i ] ) Ans = Dis[ i ] , xx = X[ i ] , yy = Y[ i ] ; printf( "(%.1lf, %.1lf).\n" , xx , yy ) ; } return 0 ;}

转载于:https://www.cnblogs.com/yzxshuaige123/archive/2013/04/21/3033886.html

你可能感兴趣的文章
开发者分享 | 从零开始开发一个即时通讯项目
查看>>
var 是 Java 开发的好朋友啊!
查看>>
提高 网站 百度权重
查看>>
最牛逼的 HTML 和 CSS 代码的背后
查看>>
apache 配置虚拟目录
查看>>
Hibernate、Mybait,Mysql、Postgresql适用场景
查看>>
WordPress表结构说明(转)
查看>>
html5 手机版页面,缩放比例调整
查看>>
Qte程序执行到app.exec()时出现Segmentation Fault问题的解决
查看>>
ceph 热迁移 live_migrate-XML error: CPU feature `pdpe1gb' specified more than once
查看>>
openstack iptables太长
查看>>
Web 通信 之 长连接、长轮询(long polling)
查看>>
python学习笔记2
查看>>
使用git命令做版本管理
查看>>
再次开篇
查看>>
Install VM Tools -- kernel header path
查看>>
主机无法访问虚拟机linux上启动的tomcat服务
查看>>
Android中this、super的区别
查看>>
ibatis log4j 配置 显示sql
查看>>
hadoop-2.3.0-cdh5.1.0完全分布式集群配置及HA配置(待)
查看>>