length = int(input()) numbers = input().split() count = [] out = 0 for i in range(length): count.append(0) for i in numbers: count[int(i)-1] += 1 while True: list_len = 0 max = [0,0] min = [0,99999999999999] for pos, val in enumerate(count): if val == 0: continue elif val > max[1]: max = [pos,val] elif val <= min[1]: min = [pos,val] for i in count: list_len += i if max[1] == 0: break elif max[1] == 1: count[max[0]] = 0 out += 1 elif max[1] > list_len/2: out+=1 break elif max[1] == min[1]: count[max[0]] = 0 count[min[0]] -= 1 out += 1 else: count[max[0]] = 0 count[min[0]] = 0 out += 1 print(out)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | length = int(input()) numbers = input().split() count = [] out = 0 for i in range(length): count.append(0) for i in numbers: count[int(i)-1] += 1 while True: list_len = 0 max = [0,0] min = [0,99999999999999] for pos, val in enumerate(count): if val == 0: continue elif val > max[1]: max = [pos,val] elif val <= min[1]: min = [pos,val] for i in count: list_len += i if max[1] == 0: break elif max[1] == 1: count[max[0]] = 0 out += 1 elif max[1] > list_len/2: out+=1 break elif max[1] == min[1]: count[max[0]] = 0 count[min[0]] -= 1 out += 1 else: count[max[0]] = 0 count[min[0]] = 0 out += 1 print(out) |