题目链接

居然1Y了,以前写的模拟退火很靠谱啊。

 #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
struct point
{
double x,y;
}p[];
int n;
int a[] = {,,-,};
int b[] = {,-,,};
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y2-y1)*(y2-y1));
}
double fun(double x,double y)
{
double ans = ;
int i;
for(i = ;i < n;i ++)
{
ans += dis(p[i].x,p[i].y,x,y);
}
return ans;
}
int main()
{
int T,i,key,num,j,k;
double tx,ty,ans,d,x,y;
srand(time(NULL));
scanf("%d",&n);
for(i = ;i < n;i ++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
key = ;
ans = ;
num = ;
x = p[].x;
y = p[].y;
T = ;
while(T--)
{
for(i = ;i <= num;i ++)
{
for(j = ;j < ;j ++)
{
k = rand()%key;
tx = x + k*a[j]*T;
ty = y + k*b[j]*T;
if(tx >= &&tx <= &&ty >= &&ty <= )
{
d = fun(tx,ty);
if(ans > d)
{
ans = d;
x = tx;
y = ty;
}
}
}
}
}
printf("%.f\n",ans);
return ;
}

最新文章

  1. jQuery.fn.extend() 与 jQuery.extend()
  2. 探 寻 宝 藏--- DP
  3. 【POJ 2942】Knights of the Round Table(点双连通分量,二分图染色)
  4. js地理位置获取、显示、轨迹绘制
  5. [转]C#使用Log4Net记录日志
  6. LitDB文章
  7. 学习NAnt Build .CS+Solution+MSBuild+SVN+NUnit+NUnitReport
  8. Getting NHibernate to generate a HiLo string ID
  9. Get current time and date on Android
  10. github上如何合并别人的pull request
  11. Ubuntu 12.04安装PPTP
  12. IWorkSpace接口介绍
  13. JS定义函数的2种方式以及区别简述(为什么推荐第二种方式)
  14. 虚拟机下Linux系统如何设置IP地址
  15. Tomcat优化方案
  16. [转]Android开发环境搭建(图文教程)
  17. 怎样使用word2013发布csdn博客
  18. Linux基础操作命令-打包压缩
  19. HDU 4348 To the moon 主席树 在线更新
  20. [BZOJ3926][ZJOI2015]诸神眷顾的幻想乡(后缀自动机)

热门文章

  1. PHP define()的用法
  2. 微软MSMQ消息队列的使用
  3. 【翻译十四】java-并发之保护块儿
  4. oracle JOB学习(一)---基础
  5. 解决css样式被内置样式覆盖的问题
  6. WPF 创建自定义窗体
  7. 遍历PspCidTable表检测隐藏进程
  8. HTML5火焰文字特效DEMO演示---转载
  9. -webkit-text-size-adjust
  10. Android常用控件之GridView与ExpandableListView的用法