(简单)搜索 HOJ 1022 Spacecraft Malfunction
来源:互联网 发布:网络购票岫岩到沈阳 编辑:程序博客网 时间:2024/06/04 19:38
Spacecraft Malfunction
Submitted : 410, Accepted : 149
It is said that court intrigues started with people lying about other people, and then lying about other people’s lying, and so it went. The intriguers constantly looked for scapegoat who inevitably proved to be someone with the least power, though not always the least morality.
We have faced a similar problem, but this time, in our malfunctioning spacecraft! There are a number of units in the spacecraft. The units are so reliable that it would surprise us very much if more than one unit were faulty. If more than one is faulty, we would lose the probe, so we are sure that exactly one unit is faulty in our spacecraft.
We know that each unit checks exactly two others, and each unit will be checked by at least one other unit. A good unit will give accurate diagnosis of the units it checks. For example, if unit X is good and it says that Y is faulty and Z is good, then, in fact, Y is faulty and Z is good. However, a bad unit is unreliable. So, if unit X is faulty and makes the same statements, then Y may or may not be good, and Z may or may not be good either. Note that a unit cannot check itself.
Now suppose that you have the reports from all units and your duty is to find which unit is indeed faulty.
Input
The first line of the input file contains a single integer t (1 <= t <=10), the number of test cases, followed by the input data for each test case. The first line of each test case contains an integer n (3 <= n <= 100), the number of units, followed by n lines each describing a unit and the result of its checks. The line starts with a positive integer number which shows the identification number of the unit. After the id number, there are two pairs of checked unit id's and check results. A check result is a single character which is either Y or N, showing whether the result of checking is good or faulty respectively. As an example, the fourth line in the Sample Input section shows that unit 16 has checked unit 8 saying it is good, and has checked unit 32 saying it is faulty.
Output
There should be one line per test case containing either the id number of the faulty unit, or the word impossible (with lower-case letters), if it is impossible to find the faulty unit from the input data.
Sample Input
152 16 Y 32 N16 8 Y 32 N32 8 N 4 Y8 4 Y 2 Y4 2 Y 16 YSample Output
32
- (简单)搜索 HOJ 1022 Spacecraft Malfunction
- HOJ 1022 Spacecraft Malfunction
- POJ 1359 Spacecraft Malfunction 笔记
- (简单)搜索 HOJ 1030 Labyrinth
- (简单) 搜索 HOJ 1044 Transportation
- (简单) 搜索 HOJ 1048 Cipher
- (简单)搜索 HOJ 1070 Word
- (简单)搜索 HOJ 1075 The Castle
- (简单) 搜索 HOJ 1066 Substrings
- (简单) 搜索 HOJ 1097 Robot
- (简单)搜索 HOJ 1692 Choose Your Own Adventure
- hdu 4158 hoj 2581 Go 简单搜索
- poj1111 hoj 1639 Image Perimeters 简单搜索
- Go hdu 4158 hoj 简单搜索
- (简单) 搜索 HOJ 1085 Finding Rectangles
- (简单) 搜索 HOJ 1105 Egyptian Multiplication
- 搜索(IDA*)HOJ The Rotation Game
- 搜索(bfs) HOJ 1448 Dungeon Master
- (中等)动态规划 HOJ 1770 Old Wine Into New Bottles
- (概念题)线段树 HOJ 1119 Atlantis
- (概念题)线段树 HOJ 1495 Area of Simple Polygons
- (概念题)线段树 HOJ 1860 Mars Maps
- (简单)线段树 HOJ 2965 Magic-Pen4
- (简单)搜索 HOJ 1022 Spacecraft Malfunction
- (简单)搜索 HOJ 1030 Labyrinth
- (简单) 搜索 HOJ 1044 Transportation
- (简单) 搜索 HOJ 1048 Cipher
- textview 使用自己的字体
- (中等) 搜索 HOJ 1049 sticks
- (简单) 搜索 HOJ 1066 Substrings
- (简单)搜索 HOJ 1070 Word
- (简单)搜索 HOJ 1075 The Castle
程序博客网,程序员的互联网技术博客家园。csdn论坛精品 msdn技术资料都在这里