[POJ 2420] A Star not a Tree?
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4058 | Accepted: 2005 |
Description
Luke lives in a loft and so is prepared to run the cables and place the hub anywhere. But he won't move his computers. He wants to minimize the total length of cable he must buy.
Input
Output
Sample Input
4
0 0
0 10000
10000 10000
10000 0
Sample Output
28284
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
#define INF 1e20
#define PI acos(-1.0)
#define N 110 struct Point
{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
};
int n;
Point p[N]; double cal(Point t)
{
double sum=;
for(int i=;i<=n;i++) sum+=sqrt((p[i].x-t.x)*(p[i].x-t.x)+(p[i].y-t.y)*(p[i].y-t.y));
return sum;
}
void solve()
{
int TN=,DN=;
Point u,v,ansp;
double ud,vd,ansd=INF;
double step=,eps=1e-,r=0.85; while(TN--)
{
u=Point(rand()%,rand()%);
ud=cal(u);
while(step>eps)
{
bool flag=;
while(flag)
{
flag=;
for(int i=;i<DN;i++)
{
double d=*PI*(double)rand()/RAND_MAX;
v.x=u.x+sin(d)*step;
v.y=u.y+cos(d)*step;
vd=cal(v);
if(vd<ud) ud=vd,u=v,flag=;
}
}
step*=r;
}
if(ud<ansd) ansd=ud,ansp=u;
}
printf("%.0f\n",ansd);
}
int main()
{
//srand((int)time(NULL)); //POJ上不能用
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
solve();
}
return ;
}
[POJ 2420] A Star not a Tree?的更多相关文章
- 三分 POJ 2420 A Star not a Tree?
题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...
- POJ 2420 A Star not a Tree? 爬山算法
B - A Star not a Tree? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...
- POJ 2420 A Star not a Tree? (计算几何-费马点)
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3435 Accepted: 172 ...
- poj 2420 A Star not a Tree?——模拟退火
题目:http://poj.org/problem?id=2420 精度设成1e-17,做三遍.ans设成double,最后再取整. #include<iostream> #include ...
- poj 2420 A Star not a Tree? —— 模拟退火
题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ...
- POJ 2420 A Star not a Tree?(模拟退火)
题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ...
- POJ 2420 A Star not a Tree?【爬山法】
题目大意:在二维平面上找出一个点,使它到所有给定点的距离和最小,距离定义为欧氏距离,求这个最小的距离和是多少(结果需要四舍五入)? 思路:如果不能加点,问所有点距离和的最小值那就是经典的MST,如果只 ...
- 【POJ】2420 A Star not a Tree?(模拟退火)
题目 传送门:QWQ 分析 军训完状态不好QwQ,做不动难题,于是就学了下模拟退火. 之前一直以为是个非常nb的东西,主要原因可能是差不多省选前我试着学一下但是根本看不懂? 骗分利器,但据说由于调参困 ...
- 【POJ】2420 A Star not a Tree?
http://poj.org/problem?id=2420 题意:给n个点,求一个点使得到这个n个点的距离和最短,输出这个最短距离(n<=100) #include <cstdio> ...
随机推荐
- Python-Day1 Python基础学习
一.Python3.5.X安装 1.Windows Windows上找度娘搜索“Python for windows下载”就OK了,安装的时候可以勾选设置环境变量,也可以安装完手动设置,这样在cmd中 ...
- 用minicom 产看 usb的串口
1 用命令 sudo apt-get install minicom 安装 2 用 minicom -s 进行配置 往下选择 Seral port setup: 然后输入 A :选择自己的 ...
- easy ui datagrid在没有数据时显示相关提示内容
$(function () { $('#dg').datagrid({ fitColumns: true, url: 'product.json', pagination: true, pageSiz ...
- 开发之前的思考-UI结构设计
UI结构设计遵循的一些要点 1.尽量不要让UI作为Camera的子物体 因为UI和摄像机敏感的关系,尽量不要将UI作为摄像机的子物体,避免出现一些因为透视(3D UI)等问题导致的视觉Bug. 2.尽 ...
- IE9下Coolite.Ext出现createContextualFragment错误
解决Ext在IE9上报错“createContextualFragment”,只需要在使用Coolite.Ext页面加入如下代码即可: if ((typeof Range !== "unde ...
- [转载]C#导入XLS数据到数据库
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> ...
- The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemK:Kinds of Fuwas
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1974 题意:问四个角都有同一个福娃的矩形有多少个. #include<b ...
- VC 最爱问的问题:你这个创业项目,如果腾讯跟进了,而且几乎是产品上完全复制,你会怎么办?
VC 最爱问的问题:你这个创业项目,如果腾讯跟进了,而且几乎是产品上完全复制,你会怎么办? http://www.zhihu.com/question/19607233 朱继玉,独立精神,自由思想. ...
- linux下c/c++ IDE开发工具介绍
为避免以下某个软件安装时不自动安装 build-essential 不妨先执行: sudo apt-get install build-essential [编辑 ]anjuta Anjuta Dev ...
- 区分JS中的undefined,null,"",0和false
在程序语言中定义的各种各样的数据类型中,我们都会为其定义一个"空值"或"假值",比如对象类型的空值null,.NET Framework中数据库 字段的空值DB ...