[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> ...
随机推荐
- spark向量
转自 1.本地向量MLlib的本地向量主要分为两种,DenseVector和SparseVector,顾名思义,前者是用来保存稠密向量,后者是用来保存稀疏向量,其创建方式主要有一下三种(三种方式均创建 ...
- 代码规范-IAR设置
1.在IAR内定义 char 2. 去掉相关的告警 3.LANGUAGE设置
- 一、记一次失败的 CAS 搭建 之 环境配置
==================================================================================================== ...
- 备份了一个nginx的虚拟主机配置文件报错
[root@localhost vhost]# service nginx restart 停止 nginx:[确定] 正在启动 nginx:nginx: [warn] conflicting ser ...
- EXTJS API
EXTJS API 链接: http://docs.sencha.com/extjs/5.0.0/ http://docs.sencha.com/extjs/4.2.2/ http://docs.se ...
- 微软职位内部推荐-Principal DEV Manager for Bing Client
微软近期Open的职位: Title: Principal DEV Manager for Bing ClientGroup: Search Technology Center Asia, BingW ...
- Notepad++ 书签
Notepad++,有一个书签功能,指定书签是Ctrl+F2,在书签之间移动是按F2来切换,这个可以在几个想查看的数据之间进行快速切换,所以看起来就很方便.
- 手工、工具分别实现cookie注入
最开始的判断access类型的网站注入点可以用“1 and 1=1”来判断. 不过现在的网站基本上被挡住了.之后呢,可以考虑cookie注入. Dim Tc_Post,Tc_Get,Tc_In,Tc_ ...
- spoj 95
栈应用 ...... 水题 #include<cstdio> #include<cstdlib> #include<cstring> #include<alg ...
- ural 1250
有点坑的dfs 看懂题应该就会做了 神圣海必然围成一个圈 dfs将神圣还外围的全部去掉 简单题 #include <cstdio> #include <cstring> ...