编程介的小学生 2017-11-22 15:13 采纳率: 20.5%
浏览 631
已采纳

Moving Bricks

Problem Description
Brickgao used to be a real tall, wealthy, handsome man and you might know him well. If you don't, please draw attention to the details below.
Brickgao tried his fortune in investment of golden bricks with his two partners LS and Jne. Because he knew little about investment he gave his total trust and bank savings to his two partners who looked smart.
However, due to the bad luck and lack of business skills, LS and Jne used up Brickgao's fund, and nothing in return. Their investment failed and the three become diaosi.
Brickgao had no other choice but to earn a living as a construction worker and he found his place on a building site moving bricks which of course was not golden ones. There were many brick fragment scattered on the site and workers had to move them to the building that under construction. Brickgao was made to cope with the task.
The problem is that the Brickgao couldn’t carry more than two bricks at a time since they were too heavy. Also, if he had taken a brick, he couldn’t put it anywhere except the goal building — his inherent sense of order does not let him do so.
You are given N pairs of coordinates of the bricks and the coordinates of the goal building. It is known that the Brickgao covers the distance between any two points in the time equal to the squared length of the segment between the points. It is also known that initially the coordinates of the Brickgao and the goal building are the same. You are asked to find such an order of bricks, that the Brickgao could move all the bricks to the building in a minimum time period. You can assume the no two bricks shared the same coordinates. If more than one optimum moving sequence Brickgao could find, he would choose the smallest lexicographic one because of the inherent sense of order.

Input
The first line of the input file contains an integer T which indicates the number of test cases. The first line of each case contains the building's coordinates x ,y. The second line contains number N (1<= N < 20) — the amount of bricks on the building site. The following N lines contain the bricks' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.

Output
For each test case, first you should print "Case x:" in a line, where x stands for the case number started with 1. Then two lines follow: the first line output the only number — the minimum time Brickgao needed to move the bricks to building, and the second line output the optimum order for Brickgao to move the bricks. Each brick in the input is described by its index number (from 1 to N).

Sample Input
2
0 0
2
1 1
-1 1
1 1
3
4 3
3 4
0 0

Sample Output
Case 1:
8
1 2
Case 2:
32
1 2 3

  • 写回答

1条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试