编程介的小学生 2017-04-11 05:42 采纳率: 20.5%
浏览 647
已采纳

Target Practice

There are many forms of contests where the contestants (shooters) try to hit targets, either moving or still. In this version there are a number of small balloons sitting on the tops of poles that are in turn stuck in the ground at various points in a large field. These poles are not all the same height. The shooter circles the field and fires at the balloons, the goal being to burst all the balloons with as few shots as possible. Since the balloons offer almost no resistance to a bullet, the bullet will pass right through and possibly hit one or more other balloons. So, by judiciously taking shots, the shooter might need only a very few shots to hit all the targets (provided the shooter is a good marksman, which we will assume is the case).

For example, the following field of 10 targets can be covered in only four shots, as shown. (The first two numbers at each position indicate the position of the balloon, and the third number the height.) Your job is to determine the fewest number of shots necessary to hit all the targets in a given field.

Input

There will be multiple test cases. Each test case will consist of an integer n (<= 50) indicating the number of target positions to follow. A value of n = 0 indicates end of input. There will follow n integer triples, x y h, indicating a balloon at position (x, y) in the field at height h. (There will be at most one balloon at any position (x, y).) All integers are greater than 0 and no greater than 100. Furthermore assume that the shooter can take shots from anywhere on the field at any height. For simplification, assume here that the balloons are points and that the bullets can pass through the poles on which the balloons are perched.

Output

Each test case should produce one line of output of the form:

Target set k can be cleared using only s shots.

where k is the number of the test case, starting at 1, and the value of s is the minimum number of shots needed to hit all the targets in the set.

Sample Input

10
5 15 4 10 60 52 17 27 4 33 20 10 33 85 31 42 52 4 70 70 22
78 88 4 85 40 58 100 75 7
9
5 15 4 10 60 52 17 27 4 33 20 10 33 85 31 42 52 4 70 70 22
78 88 4 100 75 7
0

Sample Output

Target set 1 can be cleared using only 4 shots.
Target set 2 can be cleared using only 3 shots.

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-28 15:53
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值