编程介的小学生 2017-12-09 16:03 采纳率: 20.5%
浏览 767
已采纳

Wires

Problem Description
Engineer Bob is a strange man, and he makes his floor a simple polygon and installs various fantastic machines on his floor.

On Bob’s floor, there are n machines and n sockets. Each machine is fixed at a certain location and each socket is fixed at a certain position. Different machines and socket may be located at the same position.

Bob wants to connect one machine with exactly one socket by using wire and he hopes that the total length of the wires is minimal.
In addition, we assume that:
Bob’s floor can be described by m vertices in a 2-dimentional coordinate system. The m vertices are always given by clockwise or counter-clockwise. For simplicity, the edges of the polygon are always horizontal or vertical. For example, (0,0) (0,4) (4,4) (4,0) (2,0) (2,1) (3, 1) (3,2) (1,2) (1,0) describe the polygon which is shown in Figure 1, in which M1 and M2 are machines, S1 and S2 are sockets.

Wires can only be equipped within the polygon or on the edges of the polygon. Wires can be intercrossed.

Now please find out the minimal length of all the wires needed.

Input
The input contains several cases. The first line of each case contains one integer m (1 ≤ m ≤ 100) indicating the number of vertices of the polygon. This is then followed by m lines, in which the ith line contains two integers x (0 ≤ x ≤ 10,000) and y (0 ≤ y ≤ 10,000), indicating the coordinate of the ith vertex of the polygon. And this is followed by one line, containing one integer n (1 ≤ n ≤ 16), indicating the number of machines (and also sockets).
This is followed by n lines, in which the ith line contains two integers x (0 ≤ x ≤ 10,000) and y (0 ≤ y ≤ 10,000), indicating the coordinate of the ith machine. And this is followed by n lines, in which the ith line contains two integers x (0 ≤ x ≤ 10,000) and y (0 ≤ y ≤ 10,000), indicating the coordinate of the ith socket. The input ends with m=0. It is guaranteed that the coordinates of all machines and sockets are always given within the polygon or on the edges of the polygon.

Output
For each case, output a floating-point number to two decimal places, indicating the minimal length of wires needed.

Sample Input
10
0 0
0 4
4 4
4 0
2 0
2 1
3 1
3 2
1 2
1 0
2
2 3
1 0
3 3
2 0
0

Sample Output
7.41

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-04-07 16:10
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现