Part 1
Description
Solution
The problem is similar to the traveling salesman problem, or the problem in day 9. Only in today's problem, it wraps around. So, I used the similar approach.
I split the input into for different parts: Name, gain/lose, happiness, and neighbor. With my input in A3,
B3: =LEFT(A3,SEARCH(" ",A3,1)-1)
C3: =MID(A3,SEARCH(" ",A3,SEARCH(" ",A3,1)+1)+1,4)
D3: =NUMBERVALUE(MID(A3,SEARCH(MID(A3,SEARCH(" ",A3,SEARCH(" ",A3,1)+1)+1,4),A3,1)+5,SEARCH(" ",A3,SEARCH(MID(A3,SEARCH(" ",A3,SEARCH(" ",A3,1)+1)+1,4),A3,1)+6)-(SEARCH(MID(A3,SEARCH(" ",A3,SEARCH(" ",A3,1)+1)+1,4),A3,1)+5)))
E3: =MID(A3,SEARCH("to ",A3,1)+3,SEARCH(".",A3,1)-SEARCH("to ",A3,1)-3)
F3: =IF(C3="gain",D3,0-D3)
Then, I put those into a 8×8 table, associating with each name and happiness point they get when sitting next to others. then, I make a permutations of 8 numbers, according to the seating arrangements possible, and counts the accumulated happiness point. Columns on the left are for points gained with neighbor in the left, and columns on the right are for points gained from neighbor in the right. And then, I just added them up and find the largest number.
R13: =@INDEX($R$3:$Y$10,H13,I13)
AG13: =@INDEX($R$3:$Y$10,O13,N13)
AH13: =SUM(R13:AG13)


0 komentar:
Post a Comment