Solution to G - Slow solution to H
This commit is contained in:
parent
dfc420c046
commit
5cb261deae
4 changed files with 83 additions and 0 deletions
28
bit_difference.py
Normal file
28
bit_difference.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
def xor_count(a, b):
|
||||
xor = a ^ b
|
||||
i = 0
|
||||
while xor != 0:
|
||||
i = i + (xor & 1)
|
||||
xor = xor >> 1
|
||||
return i
|
||||
|
||||
|
||||
def bitwise_difference(A):
|
||||
s = 0
|
||||
for i in range(len(A)):
|
||||
for j in range(i+1,len(A)):
|
||||
s = s + xor_count(A[i], A[j])
|
||||
return s
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.stdin.readline()
|
||||
A = sys.stdin.readline().split()
|
||||
for i in range(len(A)):
|
||||
A[i] = int(A[i])
|
||||
|
||||
print(bitwise_difference(A))
|
2
bit_difference.txt
Normal file
2
bit_difference.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
6
|
||||
34 10 52 84 0 71
|
47
counting_sheep.py
Executable file
47
counting_sheep.py
Executable file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import math
|
||||
|
||||
def digits(A, n):
|
||||
if n == 0:
|
||||
A[0] = True
|
||||
return
|
||||
|
||||
while n != 0:
|
||||
A[n % 10] = True
|
||||
n = n // 10
|
||||
|
||||
|
||||
def check(A):
|
||||
n = 0
|
||||
for i in range(10):
|
||||
if A[i]:
|
||||
n = n + 1
|
||||
return n == 10
|
||||
|
||||
|
||||
def count_sheep(start):
|
||||
if start == 0:
|
||||
return "INSOMNIA"
|
||||
|
||||
A = [False,False,False,False,False,False,False,False,False,False]
|
||||
|
||||
n = start
|
||||
while True:
|
||||
digits(A, n)
|
||||
if check(A):
|
||||
return str(n)
|
||||
n += start
|
||||
|
||||
return "INSOMNIA"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
i = 0
|
||||
for line in sys.stdin:
|
||||
if i == 0:
|
||||
i = i + 1
|
||||
continue
|
||||
print('Case #' + str(i) + ": " + count_sheep(int(line)))
|
||||
i = i + 1
|
6
counting_sheep.txt
Normal file
6
counting_sheep.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
5
|
||||
0
|
||||
1
|
||||
2
|
||||
11
|
||||
1692
|
Reference in a new issue