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个点的距离之和最小. 分析:一开始看到这个题想必 ...
随机推荐
- 在mac上独立安装PHP环境
1.http://dditblog.com/blog_418.html 2.http://www.jianshu.com/p/0456dd3cc78b
- 【BZOJ4358】permu kd-tree
[BZOJ4358]permu Description 给出一个长度为n的排列P(P1,P2,...Pn),以及m个询问.每次询问某个区间[l,r]中,最长的值域连续段长度. Input 第一行两个整 ...
- WinForm开发----关闭window窗体最好的办法
最近有一人问道,如何切换窗体.一想到这,我就想,不就是new一个form,然后就show么? 可是我发现,当你控制某个属性的时候,不是不能控制,只是很麻烦而已.有没有好的办法?当然有,咋办? 最简单最 ...
- Hadoop生态优秀文章集锦
如何用形象的比喻描述大数据的技术生态?Hadoop.Hive.Spark 之间是什么关系? https://www.zhihu.com/question/27974418 HBase 和 Hive 的 ...
- devexpress gridcontrol如何遍历每一行
List<Medicine> medicinelist = new List<Medicine>(); foreach (GridViewRow row in GridView ...
- OWASP-A5-安全配置错误
1.安全配置错误 安全配置错误可以发生在一个应用程序堆栈的任何层面,包括平台.Web服务器.应用服务器.数据库.框架和自定义代码. 开发人员和系统管理员需共同努力,以确保整个堆栈的正确配置.自动扫描器 ...
- 我的Android进阶之旅------>WindowManager.LayoutParams介绍
本文转载于: http://hubingforever.blog.163.com/blog/static/171040579201175111031938/ 本文参照自: http://develop ...
- Android底部菜单栏+顶部菜单
底部菜单栏+顶部菜单(wechat)demo http://blog.csdn.net/evankaka/article/details/44121457 底部菜单demo http://blog.c ...
- eclipse revert resources 很慢的解决办法
eclipse启动无响应,停留在Loading workbench状态,或老是加载不了revert resources 做开发的同学们或多或少的都会遇到eclipse启动到一定程度时,就进入灰色无响应 ...
- C# 汉字编码GB2312转换
功能界面 源码: using System; using System.Collections.Generic; using System.ComponentModel; using System.D ...