求解决-入门小白求解北京2004ACM的Square题

问题描述

入门小白求解北京2004ACM的Square题

入门小白开始啃题,然而啃不动(无奈摊手)
求大神帮忙解答(最好是有解释啦)(?>ω<*?)
SquareTime Limit:?1000ms,?Special Time Limit:2500ms,?Memory Limit:32768KBTotal submit users:?177,?Accepted users:?26Problem 10002 :?No special judgementProblem descriptionGiven a square at [0, 1] * [0, 1] that has N points ( P1, P2, ..., PN?) in the square (you may assume that different points can be at the same position), we can connect the N points and the four corners of the square with some line segments so that through these segments any two of the N+4 points can reach each other (directly or indirectly). The graph length is defined as the total length of the line segments. When N points' positions are fixed, there must exist a way of connecting them, such that it will make the shortest graph length. We can use LEN (P1, P2, ..., PN) to record the graph length using this way of connecting.?

In this situation, LEN (P1, P2, ..., PN) is a function of P1, P2, ..., PN. When P1, P2, ..., PN?change their positions, LEN (P1, P2, ..., PN) also changes. It's easy to prove that there exist some P1', P2', ..., PN' in the square such that LEN (P1', P2', ..., PN') is at its minimum.?

Given the initial positions of N points, your task is to find out N points P1", P2", ..., PN" in the square such that |P1P1"| + |P2P2"| + ... + |PNPN"| is minimum and LEN (P1", P2", ..., PN") = LEN (P1', P2', ..., PN') . You are requested to output the value of |P1P1"| + |P2P2"| + ... + |PNPN"|, where |PiPi"| is the distance between Pi and Pi".?
??
For example, Figure-1 gives the initial position of P1?and the way of connecting to obtain LEN (P1). In Figure-2, it gives the position of P1", which is at the center of the square, and the way of connecting to obtain LEN (P1"). It can be proved that LEN (P1") = LEN (P1?); your job is to output the distance between P1?and P1".

InputThe input consists of several test cases. For each test case, the first line consists of one integer N (1 <= N <= 100), the number of points, and N lines follow to give the coordinates for every point in the following format:?
x y?

Here, x and y are float numbers within the value [0, 1].?

A test case of N = 0 indicates the end of input, and should not be processed.?

OutputFor each test case, output the value of |P1P1"| + |P2P2"| + ... + |PNPN"|. The value should be rounded to three digits after the decimal point.

Sample Input1 0.2 0.5 2 0 0.5 0.5 0.5 0Sample Output0.300 0.500Judge Tips费马点

Problem SourceBeijing?2004

解决方案

http://www.cnblogs.com/rocketfan/archive/2009/05/20/1467236.html

时间: 2024-09-24 12:22:56

求解决-入门小白求解北京2004ACM的Square题的相关文章

小白求解正则表达式遇到的问题

问题描述 小白求解正则表达式遇到的问题 GetShow(2f54d4f7-7431-42fe-9f7e-70e262b9ddc4,)>阳光绿色食品有限公司<>;<>详细地址:安徽岳西县中关乡<>联系电话:0556-2463256<><> 上边字段 我想要截取 阳光绿色食品有限公司 这个正则表达式该怎么写呢? 我写的正则是 ">(.+?)<>;" 获取公司名称)>阳光绿色食品有限公司<>

java小白求解,下面的代码是按照书上的例子抄下来的,不明白为什么报错。

问题描述 java小白求解,下面的代码是按照书上的例子抄下来的,不明白为什么报错. 代码如下:主要问题就是报错的地方:已经用注释吧报错贴上:还看不懂这个报错,求大神帮助:package Calendar; import java.util.Scanner; public class Calendar { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println(

c语言-一段简单的程序,就是想不通,好像有些漏洞,求解决,我是好奇宝宝

问题描述 一段简单的程序,就是想不通,好像有些漏洞,求解决,我是好奇宝宝 #include using namespace std; void main() { int n,reverse = 0,rem,temp; printf("enter an integer: "); scanf("%d",&n); temp = n; while(temp!=0) { rem = temp%10; reverse = reverse*10+rem; temp/=10

js 兼容性-有个js代码,火狐浏览器可以实现,谷歌不行,求解决

问题描述 有个js代码,火狐浏览器可以实现,谷歌不行,求解决 用js写了一个切换样式的(用下拉框选择样式切换).但是在火狐浏览器可以实现切换,在谷歌和360浏览器就没有反应.求教大神指导.下面是有关代码,有些没有关系的我就删了. //皮肤样式切换 function switchStylestyle(styleName){ aa=document.styleSheets; for(i=0;i<aa.length;i++){ aa[i].disabled=true; if(aa[i].title==

这是为什么-这是什么鬼???今天突然这样了,,,小白求解

问题描述 这是什么鬼???今天突然这样了,,,小白求解 今天用vc6,0编程的时候怎么运行时这样了???怎么弄???关了重启还是这样,,,求大神,,, 解决方案 中止. 看上去是说有个变量c没有初始化导致的. 解决方案二: g梵蒂冈的股份方式德国法国 解决方案三: 出现这个说明你写的程序出现了问题,根据提示,应该是某个名为'c'的变量没有初始化导致的 解决方案四: 出现这个说明你写的程序出现了问题,根据提示,应该是某个名为'c'的变量没有初始化导致的

mysql-Parameter index out of range 好心人求解决在线等 急

问题描述 Parameter index out of range 好心人求解决在线等 急 代码如下 求解哪里错误 package com.pact.mobilestore; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import jav

求高手-手机用户界面被删,求解决。………………

问题描述 手机用户界面被删,求解决.------ 刷机不小心把用户界面删了,状态通知栏不显示了,求高手解决,难道俺得去换个手机了. 解决方案 看下,手机设置中的恢复出厂设置/恢复镜像还能不能用. 再不行看看厂商有没有刷机包,或者拿维修点. 再不行就换一个.一般手机过了质保,也不值钱了. 解决方案二: 1.自己尝试恢复,手机里面有恢复原厂设置的,一般的故障都能处理,注意做好重要数据的备份 2.实在解决不掉联系当地特约维修点,看能否简单维修一下 解决方案三: 直接找售后吧.自己刷机不在保修范围,自己

java-用HQLhelper方式,然后报错,求解决。

问题描述 用HQLhelper方式,然后报错,求解决. 因为在hql语句中2个占位符几个.我查了百度,query.setparameter就可以解决.可是我写的是HQLhelper- 解决方案 ClickOnce 部署中报错的解决方式squid日志报错信息的解决方式启动服务器报错,求解决

Android初学者,求解决这个URI解析

问题描述 Android初学者,求解决这个URI解析 打印出来的信息是读取的同一张图片,选择图库里的就可以获取到,选择其他的就报null 解决方案 http://blog.csdn.net/ljz2009y/article/details/7678027