Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi/főiskolai kategória, 2016. december 4.

December 4, 2016 10:10 AM – December 4, 2016 3:10 PM

The Triangle Game

In the triangle game, you start off with six triangles numbered on each edge, as in the example above. You can slide and rotate the triangles so they form a hexagon, but the hexagon is only legal if edges common to two triangles have the same number on them. You may not flip any triangle over. Two legal hexagons formed from the six triangles are illustrated below:

The score for a legal hexagon is the sum of the numbers on the outside six edges.

Your problem is to find the highest score that can be achieved with any six particular triangles.

Input Specification

The input will contain one or more test cases. Each test case is a sequence of six lines with three integers from 1 to 100, separated by blanks on each line. Each line contains the numbers on the triangles in clockwise order. Test cases are separated by a line containing only an asterisk. The last test case is followed by a line containing only a dollar sign.

Output Specification

For each test case, the output is a line containing only the word “none” if there are no legal hexagons or the highest score if there is a legal hexagon.

Sample Input

  1. 1 4 20
  2. 3 1 5
  3. 50 2 3
  4. 5 2 7
  5. 7 5 20
  6. 4 7 50
  7. *
  8. 10 1 20
  9. 20 2 30
  10. 30 3 40
  11. 40 4 50
  12. 50 5 60
  13. 60 6 10
  14. *
  15. 10 1 20
  16. 20 2 30
  17. 30 3 40
  18. 40 4 50
  19. 50 5 60
  20. 10 6 60
  21. $
download as text file

Output for Sample Input

  1. 152
  2. 21
  3. none
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019