poj-2420 A Star not a Tree?(模拟退火算法)
题目链接:
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 5219 | Accepted: 2491 |
Description
Unfortunately, Luke cannot use his existing cabling. The 100mbs system uses 100baseT (twisted pair) cables. Each 100baseT cable connects only two devices: either two network cards or a network card and a hub. (A hub is an electronic device that interconnects several cables.) Luke has a choice: He can buy 2N-2 network cards and connect his N computers together by inserting one or more cards into each computer and connecting them all together. Or he can buy N network cards and a hub and connect each of his N computers to the hub. The first approach would require that Luke configure his operating system to forward network traffic. However, with the installation of Winux 2007.2, Luke discovered that network forwarding no longer worked. He couldn't figure out how to re-enable forwarding, and he had never heard of Prim or Kruskal, so he settled on the second approach: N network cards and a hub.
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
题目:求一个多边形的费马点到所有点的距离和,费马点是多边形内到顶点距离和最短的点;
思路:更poj1379一个人思路,用模拟退火算法找费马点求距离;
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
using namespace std;
const int num=;
const int cnt=;
const double PI=acos(-1.0);
const double inf=1e12;
struct node
{
double px,py,dis;
};
node ans[];
int n;
double x[],y[];
double get_dis(double a,double b,double c,double d)
{
return sqrt((c-a)*(c-a)+(d-b)*(d-b));
}
void Iint()
{
for(int i=;i<num;i++)
{
ans[i].px=1.0*(rand()%)/*;
ans[i].py=1.0*(rand()%)/*;
ans[i].dis=;
for(int j=;j<n;j++)
{
ans[i].dis+=get_dis(ans[i].px,ans[i].py,x[j],y[j]);
}
}
}
int main()
{
srand((unsigned)time(NULL));
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%lf%lf",&x[i],&y[i]);
}
Iint();
double temp=get_dis(,,,);
while(temp>0.2)
{
for(int i=;i<num;i++)
{
double fx,fy;
for(int j=;j<cnt;j++)
{
double cur=2.0*PI*(rand()%)/;
fx=ans[i].px+cos(cur)*temp;
fy=ans[i].py+sin(cur)*temp;
if(fx<||fx>||fy<||fy>)continue;
double dist=;
for(int k=;k<n;k++)
{
dist+=get_dis(fx,fy,x[k],y[k]);
}
if(dist<ans[i].dis)
{
ans[i].px=fx;
ans[i].py=fy;
ans[i].dis=dist;
}
}
}
temp*=0.8;
}
double ans_dis=inf;
int ans_x,ans_y;
for(int i=;i<num;i++)
{
if(ans[i].dis<ans_dis)
{
ans_dis=ans[i].dis;
}
}
printf("%.0lf\n",ans_dis);
return ;
}
poj-2420 A Star not a Tree?(模拟退火算法)的更多相关文章
- 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? —— 模拟退火
题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ...
- 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?(模拟退火)
题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ...
- 三分 POJ 2420 A Star not a Tree?
题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...
- [POJ 2420] A Star not a Tree?
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4058 Accepted: 200 ...
- 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?【爬山法】
题目大意:在二维平面上找出一个点,使它到所有给定点的距离和最小,距离定义为欧氏距离,求这个最小的距离和是多少(结果需要四舍五入)? 思路:如果不能加点,问所有点距离和的最小值那就是经典的MST,如果只 ...
- Poj2420 A Star not a Tree? 模拟退火算法
题目链接:http://poj.org/problem?id=2420 题目大意:每组数据中给n个点(n<=100),求平面中一个点使得这个点到n个点的距离之和最小. 分析:一开始看到这个题想必 ...
随机推荐
- 嵌入式开发之davinci--- 8148/8168/8127 中的High-DefinitionVideo Processing Subsystem (HDVPSS)
High-DefinitionVideo Processing Subsystem (HDVPSS) 这一章介绍了高清视频处理子系统(HDVPSS). 2.1导论 2.1.1 简介 HDVPSS 使用 ...
- 使用 SourceTree 遇到冲突的解决方法
首先,更新代码之前先 git stash ,然后 git pull ,再 git stash pop 这时候如果本地改的代码跟线上的冲突了,就报错了.那么就需要手动解决冲突. 打开存在冲突的文件,会看 ...
- yii2.0 中的队列
a yii2 extension to make simple to use queue. yii2-queue让队列的使用在yii2中变得更轻松,她为各种队列组件的使用提供了一个标准的接口,您只需要 ...
- jqcloud 标签云效果
官网地址: http://mistic100.github.io/jQCloud/index.htmlgithub 地址: https://github.com/lucaong/jQCloud使用 & ...
- Jaxb2 实现JavaBean与xml互转
一.简介 JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术.该过程中,JAXB也提供了将XML实 ...
- 【python】-- 基本语法、循环
数据类型 1.数字: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位系统上,整数的位数为64位,取 ...
- 【python】-- try except (异常捕获)、断言
try except (异常捕获) 当程序出错了,但是我们又不想让用户看到这个错误,而且我在写程序的时候已经预料到了它可以出现这样的错误,出现这样的错误代表着什么,我们可以提前捕获这些个错误 1.异常 ...
- GPL 与 LGPL 扫盲
本文部分摘自评论:从射手QQ之争看开源许可证的选择 首先,开源并不代表放弃自身的权力,相反,开源软件之所以存在,正是它非常注重这种权力,并且把这种权力赋予了软件的所有使用者.小心的选择许可证是开发开 ...
- struts自定义拦截器实现
示例 添加新功能:只有是登录的状态访问hello_loginSuccess才会显示登录成功. index.jsp登录成功页面 test.jsp登录页面 一.修改原代码实现 1.登录后将登录信息添加到S ...
- 坑爹的shell 空格
shell 空格很敏感,被线上代码坑了,占个位,回头好好整理一下