编程介的小学生 2019-11-21 23:45 采纳率: 20.5%
浏览 105

Finding Treasure 是怎么实现的呢

Description

Once upon a time, there was a young man who loved adventure. He found an old lambskin in his grandfather's relic which described a secret buried treasure. The old lambskin told him to go to a particular deserted island. There was a big stretch of lawn on the north shore of the island. On the lawn there was an oak tree, a pine tree and a gallows. The instructions were as following: Walk from the gallows to the oak tree and remember the distance, turn right and walk the same distance, and make a mark there. Then return to the gallows, walk towards the pine tree and remember the distance, turn left and walk the same distance, and also make a mark. Excavate at the middle point of the segment between the two marks, and the treasure will be there (see Figure 1).

Figure 1

The young man found that island and also found the oak tree and the pine tree, but the gallows was destroyed due to the abrasion of time. The young person was disappointed and went back. What a pity! If the young man had some geometry knowledge, he would discover that the position of the treasure is independent from the position of the gallows. But I believe you will not make similar mistakes. Given a general description of how to find the treasure, your job is to find the position of the treasure, if the position can be fixed.

First you will be given some points of original marks. The positions of some of these points are known, but the others are unknown. Then you will be given some instructions to make new marks. There are three kinds of instructions:
Given two marks A and B, the new mark is at the middle point between A and B.
Given two marks A and B, walk from A to B, turn left, walk the same distance as the distance between A and B, and then make a mark.
Given two marks A and B, walk from A to B, turn right, walk the same distance as the distance between A and B, and then make a mark.

At last, you will be asked for the position of a mark.
Input

There are several test cases. Each test case has three parts of input. The first part contains several lines indicating the original marks with the one of the following two formats:
M

or:
M x y

Here M is the mark symbol, and x and y are integers in the range of [0, 100]. The first format means that we don't know the position of the mark. The second format means that we know the position of the mark is (x, y). In this part, one mark will be mentioned at most once.

The second part contains some instructions with the following formats:
N A B C

Here N (= 1, 2 or 3) indicates which kind of instruction is used. A, B are symbols of the marks you have already had, and C is the symbol of a new mark you will get. You may assume that A and B are different marks and have been mentioned before, and it's the first time for C to show up.

The third part is one line containing a mark symbol, of which we want to know the position. It is assured that this mark has been mentioned before.

A line with "END" indicates the end of the input.

To make it easier, we use 'A', 'B', ... and 'Z' as mark symbols, which implies there are no more than 26 marks.
Output

For each test case, output one line containing two decimal numbers x and y, which means (x, y) is the position we want to know. These numbers should be rounded two digits after the decimal point. If the position is uncertain, output "UNCERTAIN!" instead.
Sample Input

B 0 0
A
C 100 0
3 A B D
2 A C E
1 D E F
F
END
Sample Output

50.00 50.00

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题