编程介的小学生 2017-11-17 06:03 采纳率: 20.5%
浏览 464
已结题

Starsloop System Problem

Problem Description
At the end of the 200013th year of the Galaxy era, the war between Carbon-based lives and Silicon civilization finally comes to its end with the Civil Union born from the ruins. The shadow fades away, and the new-born Union is opening a new page.

Although the war ended, the affect of the war is far from over. Now the council is busy fixing the transportation system. Before the war, all the stars were connected with artificial wormholes which were destroyed during the war. At the same time, natural wormholes are breaking down with the growing traffic. A new traffic system is on the schedule.

As two civilizations combine, the technology integrates. Scientists find a new traffic system called the Starloop System.

This system is made up of several starloops. People build a starway to connect two stars. A startloop is a closed path with no repetitions of stars or starways allowed, other than the repetition of the starting and ending star. And a starloop contains at least two starts and two starways. A startloop's cost is the sum of the length of all the starways in it. Length of a starway connecting two stars is floor(x), which x is the euclidean distance between two stars. You can build more than one starway between any two stars, but one starway can only belongs to one starloop.

As the picture above shows, there are two starloops. One is blue and the other one is brown.

As a starloop is set up, each star on the starloop will get a unit of star-energy. So the two blue stars can get one unit of star-energy, and at the same time the black two stars can get two units because they both belong to two starloops. When a star earns a certain number of energy units, the transporter on that star will be activated. One can easily travel between any two stars whose transporter is activated.

Now the council wants to know the minimal cost to build a starloop system on all the stars . In other words, every star's transporter should be activated

Input
There are multiple test cases.
For each test case:
There is a line with one integer n which is the number of stars.

The following n lines each describes a star by four integers xi, yi, zi and wi, defined as the spatial coordinate and the number of energy units the star needs to activate the transporter. Please NOTE that getting more than wi energy units will put the star in a dangerous situation, so it is not allowed.
The input ends with n = 0.

1<=n<=100
|xi|,|yi|,|zi|<=200
wi<=50

Output
For each test case, output one line that contains an integer equals to the minimal cost you can get. If there is no solution, just output -1;

Sample Input
3
0 0 2 1
0 2 0 1
2 0 0 1
3
0 0 2 2
0 2 0 1
2 0 0 1
3
0 0 2 3
0 2 0 1
2 0 0 1
0

Sample Output
6
8
-1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?