2019-12-17-cpe-第7題-uva11987
題目:https://onlinejudge.org/external/119/p11987.pdf
首先是官方的解答
我的Code
我的想法是用陣列來存取該數字的集合
讓index作為數字 而 array[index]作為該數字所屬的集合
EX(sample input) :
5 7 | set[0] = 0 , set[1] = 1 , set[2] = 2 , set[3] = 3 , set[4] = 4
1 1 2 | set[0] = 1 , set [1] = 1 , set[2] = 2 , set[3] = 3 , set[4] = 4
2 3 4 | set[0] = 1 , set [1] = 1 , set[2] = 3 , set[3] = 3 , set[4] = 4
1 3 5 | set[0] = 1 , set [1] = 1 , set[2] = 4 , set[3] = 4 , set[4] = 4
3 4 | set[4-1] = 4 -> set[2] = 4 , set[3] = 4 , set[4] = 4 -> 3 + 4 + 5 -> output 3 12
2 4 1 | set[0] = 1 , set [1] = 1 , set[2] = 4 , set[3] = 1 , set[4] = 4
3 4 | set[4-1] = 1 -> set[0] = 1 , set [1] = 1 , set[4] = 1 -> 1 + 2 + 4 -> output 3 7
3 3 | set[3-1] = 4 -> set[2] = 4 , set[4] = 4 -> 3 + 5 -> output 2 8