如何使用动态编程解决Friends Circle问题

时间:2019-07-13 04:48:10

标签: algorithm

2N个朋友(A,B,C ...,2N)站在圈子中。正好有一个人站在另一个人的对面。其中一些朝内,一些朝外。鉴于某些事实,我们的任务是建立常任职位并回答一些问题。如果无法进行安排或可能进行不止一种安排,请打印“不可能安排”。

Facts
"1AB" means : A and B are standing adjacent to each other 
"2AB" means : A and B are standing opposite to each other 
"3AB" means : A is standing to the immediate left of B
"4AB" means : A is standing to the immediate right of B
"5A" means : A is facing inwards
"6A" means : A is facing outwards
"7n" means : n peoples are facing inwards, where n is a number
"8n" means : n peoples are facing outwards, where n is a number


Questions
"?2A" means : who is standing opposite of A
"?3A" means : who is standing to the immediate left of A
"?4A" means : who is standing to the immediate right of A
"?5A" means : is A facing inwards?Ans: Y/N
"?6A" means : is A facing outwards?Ans: Y/N

Constraints
1<N<10
1< TOTAL FACTS < 30
1 < Total Questions < 20


Input Format
N multiple facts, separated by semicolon multiple questions separated by semicolon

Explanation

Example 1

Input
2
2AB;72;1AC;6D;4BD;6C
?2D;?3C;?4B;?5A;?6B

output
C;B;D;Y;N

Explanation
4 people are A, B, C and D are standing in a circle
There are 6 facts separated by semicolon
2AB > A and B are standing opposite
72 >  2 people are facing inwards
1AC >  A and C are standing nearby
6D > D is facing outwards
4BD > B is standing immediate right of D
6C > C is facing outwards

0 个答案:

没有答案