A Star not a Tree?
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4058   Accepted: 2005

Description

Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allow you to connect any number of computers together in a linear arrangement. Luke is particulary proud that he solved a nasty NP-complete problem in order to minimize the total cable length.  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

The first line of input contains a positive integer N <= 100, the number of computers. N lines follow; each gives the (x,y) coordinates (in mm.) of a computer within the room. All coordinates are integers between 0 and 10,000.

Output

Output consists of one number, the total length of the cable segments, rounded to the nearest mm.

Sample Input

  1. 4
  2. 0 0
  3. 0 10000
  4. 10000 10000
  5. 10000 0

Sample Output

  1. 28284

Source

Waterloo Local 2002.01.26
 
模拟退火算法、网上各种写法、晕死、都不知道哪个是对的了、
数据弱、乱写的、AC了、
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <cstdlib>
  7. using namespace std;
  8. #define INF 1e20
  9. #define PI acos(-1.0)
  10. #define N 110
  11.  
  12. struct Point
  13. {
  14. double x,y;
  15. Point(){}
  16. Point(double x,double y):x(x),y(y){}
  17. };
  18. int n;
  19. Point p[N];
  20.  
  21. double cal(Point t)
  22. {
  23. double sum=;
  24. 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));
  25. return sum;
  26. }
  27. void solve()
  28. {
  29. int TN=,DN=;
  30. Point u,v,ansp;
  31. double ud,vd,ansd=INF;
  32. double step=,eps=1e-,r=0.85;
  33.  
  34. while(TN--)
  35. {
  36. u=Point(rand()%,rand()%);
  37. ud=cal(u);
  38. while(step>eps)
  39. {
  40. bool flag=;
  41. while(flag)
  42. {
  43. flag=;
  44. for(int i=;i<DN;i++)
  45. {
  46. double d=*PI*(double)rand()/RAND_MAX;
  47. v.x=u.x+sin(d)*step;
  48. v.y=u.y+cos(d)*step;
  49. vd=cal(v);
  50. if(vd<ud) ud=vd,u=v,flag=;
  51. }
  52. }
  53. step*=r;
  54. }
  55. if(ud<ansd) ansd=ud,ansp=u;
  56. }
  57. printf("%.0f\n",ansd);
  58. }
  59. int main()
  60. {
  61. //srand((int)time(NULL)); //POJ上不能用
  62. while(scanf("%d",&n)!=EOF)
  63. {
  64. for(int i=;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
  65. solve();
  66. }
  67. return ;
  68. }

[POJ 2420] A Star not a Tree?的更多相关文章

  1. 三分 POJ 2420 A Star not a Tree?

    题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...

  2. 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 ...

  3. POJ 2420 A Star not a Tree? (计算几何-费马点)

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3435   Accepted: 172 ...

  4. poj 2420 A Star not a Tree?——模拟退火

    题目:http://poj.org/problem?id=2420 精度设成1e-17,做三遍.ans设成double,最后再取整. #include<iostream> #include ...

  5. poj 2420 A Star not a Tree? —— 模拟退火

    题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ...

  6. POJ 2420 A Star not a Tree?(模拟退火)

    题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ...

  7. POJ 2420 A Star not a Tree?【爬山法】

    题目大意:在二维平面上找出一个点,使它到所有给定点的距离和最小,距离定义为欧氏距离,求这个最小的距离和是多少(结果需要四舍五入)? 思路:如果不能加点,问所有点距离和的最小值那就是经典的MST,如果只 ...

  8. 【POJ】2420 A Star not a Tree?(模拟退火)

    题目 传送门:QWQ 分析 军训完状态不好QwQ,做不动难题,于是就学了下模拟退火. 之前一直以为是个非常nb的东西,主要原因可能是差不多省选前我试着学一下但是根本看不懂? 骗分利器,但据说由于调参困 ...

  9. 【POJ】2420 A Star not a Tree?

    http://poj.org/problem?id=2420 题意:给n个点,求一个点使得到这个n个点的距离和最短,输出这个最短距离(n<=100) #include <cstdio> ...

随机推荐

  1. spark向量

    转自 1.本地向量MLlib的本地向量主要分为两种,DenseVector和SparseVector,顾名思义,前者是用来保存稠密向量,后者是用来保存稀疏向量,其创建方式主要有一下三种(三种方式均创建 ...

  2. 代码规范-IAR设置

    1.在IAR内定义 char 2. 去掉相关的告警 3.LANGUAGE设置

  3. 一、记一次失败的 CAS 搭建 之 环境配置

    ==================================================================================================== ...

  4. 备份了一个nginx的虚拟主机配置文件报错

    [root@localhost vhost]# service nginx restart 停止 nginx:[确定] 正在启动 nginx:nginx: [warn] conflicting ser ...

  5. EXTJS API

    EXTJS API 链接: http://docs.sencha.com/extjs/5.0.0/ http://docs.sencha.com/extjs/4.2.2/ http://docs.se ...

  6. 微软职位内部推荐-Principal DEV Manager for Bing Client

    微软近期Open的职位: Title: Principal DEV Manager for Bing ClientGroup: Search Technology Center Asia, BingW ...

  7. Notepad++ 书签

      Notepad++,有一个书签功能,指定书签是Ctrl+F2,在书签之间移动是按F2来切换,这个可以在几个想查看的数据之间进行快速切换,所以看起来就很方便.

  8. 手工、工具分别实现cookie注入

    最开始的判断access类型的网站注入点可以用“1 and 1=1”来判断. 不过现在的网站基本上被挡住了.之后呢,可以考虑cookie注入. Dim Tc_Post,Tc_Get,Tc_In,Tc_ ...

  9. spoj 95

    栈应用 ...... 水题 #include<cstdio> #include<cstdlib> #include<cstring> #include<alg ...

  10. ural 1250

    有点坑的dfs  看懂题应该就会做了 神圣海必然围成一个圈  dfs将神圣还外围的全部去掉   简单题 #include <cstdio> #include <cstring> ...