Skip to content

Commit aea869a

Browse files
committed
COUT-2K18
1 parent 0e9324f commit aea869a

File tree

13 files changed

+418
-46
lines changed

13 files changed

+418
-46
lines changed

CP/ March Challenge 2018/p4.py

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,30 @@ def readIntsindex0():
88
def readStr():
99
return raw_input()
1010

11-
def binarySearch (arr, l, r, x):
12-
13-
# Check base case
14-
if r >= l:
15-
16-
mid = l + (r - l)/2
17-
18-
# If element is present at the middle itself
19-
if arr[mid] == x:
20-
return mid
21-
22-
# If element is smaller than mid, then it
23-
# can only be present in left subarray
24-
elif arr[mid] > x:
25-
return binarySearch(arr, l, mid-1, x)
26-
27-
# Else the element can only be present
28-
# in right subarray
29-
else:
30-
return binarySearch(arr, mid+1, r, x)
31-
32-
else:
33-
# Element is not present in the array
34-
return -1
3511

3612
for __ in range(readInt()):
3713
n,h = readInts()
38-
arr = readInts()
39-
summ = 0
40-
for i in arr:
41-
summ+=i
42-
arr = sorted(arr)
43-
summ = float(summ)
44-
minn = int(math.ceil(summ/h))
45-
maxn = arr[n-1]
14+
a = readInts()
15+
a = sorted(a)
16+
print(a)
17+
# summ = 0
18+
# for i in range(n):
19+
# summ+= a[i]
20+
diff = h-n
4621
if(n==h):
47-
print(arr[n-1])
22+
print(a[n-1])
4823
continue
49-
# print(minn)
50-
for i in range(minn,maxn+1):
51-
s=0
52-
for j in reversed(arr):
53-
if(j > i):
54-
s+=(int(math.ceil(j/i))-1)
55-
else:
56-
break
57-
if(n+s<=h):
58-
print(i)
24+
for i in range(diff):
25+
print("yeh waala hai ", a[n+i-1])
26+
if(a[n+i-1]/2<=1):
5927
break
60-
# # print("loda")
28+
j = a[n+i-1]/2
29+
a[n+i-1] -= j
30+
a.append(j)
31+
a = sorted(a)
32+
print(a)
33+
# di = i
34+
print(int(a[n+i]))
6135

6236

6337
'''
@@ -67,9 +41,34 @@ def binarySearch (arr, l, r, x):
6741
4 5
6842
4 3 2 100
6943
70-
Output:
44+
1
45+
4 6
46+
4 3 2 100
47+
48+
1
49+
7 15
50+
1 1 1 1 1 1 1
51+
52+
1
53+
5 12
54+
232 43 213 2431 431
55+
56+
1
57+
4 5
58+
4 3 2 7
59+
7160
3
61+
3 3
62+
1 2 3
63+
3 4
64+
1 2 3
65+
4 5
66+
4 3 2 7
67+
7268
2
73-
4
69+
6 9
70+
12 35 45 34 32 213
71+
4 5
72+
4 3 2 7
7473
7574
'''

CP/ March Challenge 2018/p41.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import math
2+
def readInts():
3+
return list(map(int, raw_input().strip().split()))
4+
def readInt():
5+
return int(raw_input())
6+
def readIntsindex0():
7+
return list(map(lambda x: int(x) - 1, input().split()))
8+
def readStr():
9+
return raw_input()
10+
11+
for __ in range(readInt()):
12+
n,h = readInts()
13+
a = readInts()
14+
a = sorted(a)
15+
diff = h-n
16+
if(n==h):
17+
print(a[n-1])
18+
continue
19+
for i in range(diff):
20+
if(a[n+i-1]/2<=1):
21+
break
22+
j = a[n+i-1]/2
23+
a[n+i-1] -= j
24+
a.append(j)
25+
a = sorted(a)
26+
print(int(a[n+i]))
27+
28+
29+
'''
30+
31+
Input:
32+
1
33+
4 5
34+
4 3 2 100
35+
36+
1
37+
4 6
38+
4 3 2 100
39+
40+
1
41+
7 15
42+
1 1 1 1 1 1 1
43+
44+
1
45+
5 12
46+
232 43 213 2431 431
47+
48+
1
49+
4 5
50+
4 3 2 7
51+
52+
3
53+
3 3
54+
1 2 3
55+
3 4
56+
1 2 3
57+
4 5
58+
4 3 2 7
59+
60+
2
61+
6 9
62+
12 35 45 34 32 213
63+
4 5
64+
4 3 2 7
65+
66+
'''

CP/ March Challenge 2018/p5.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import math
2+
def readInts():
3+
return list(map(int, raw_input().strip().split()))
4+
def readInt():
5+
return int(raw_input())
6+
def readIntsindex0():
7+
return list(map(lambda x: int(x) - 1, input().split()))
8+
def readStrs():
9+
return raw_input().split()
10+
def readStr():
11+
return raw_input()
12+
13+
for __ in range(readInt()):
14+
15+
16+
17+
18+
19+
'''
20+
Input:
21+
22+
5 3
23+
20 11 18 2 13
24+
1 3
25+
3 5
26+
2 4
27+
28+
Output:
29+
30+
2147483629
31+
2147483645
32+
2147483645
33+
34+
'''

CP/COUT-2K18/p1.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import math
2+
def readInts():
3+
return list(map(int, raw_input().strip().split()))
4+
def readInt():
5+
return int(raw_input())
6+
def readIntsindex0():
7+
return list(map(lambda x: int(x) - 1, input().split()))
8+
def readStrs():
9+
return raw_input().split()
10+
def readStr():
11+
return raw_input()
12+
13+
14+
for __ in range(readInt()):
15+
a = readStr()
16+
n = len(a)
17+
vowels,cons =0,0
18+
for i in range(n):
19+
if(a[i] in 'aeiou'):
20+
vowels+=1
21+
elif(a[i] in 'bcdfghjklmnpqrstvwxyz'):
22+
cons+=1
23+
print vowels,cons
24+
25+
# a = 'a'
26+
# vowels =''
27+
# cons = ''
28+
# for i in range(26):
29+
# if(chr(ord(a)+i) in 'aeiou'):
30+
# vowels += chr(ord(a)+i)
31+
# else:
32+
# cons += chr(ord(a)+i)
33+
# print(vowels)
34+
# print(cons)
35+
36+
'''
37+
Input
38+
39+
3
40+
abcde ewa
41+
aioue
42+
Aefdd
43+
44+
Output
45+
46+
2 3
47+
5 0
48+
49+
'''

CP/COUT-2K18/p2.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import math
2+
def readInts():
3+
return list(map(int, raw_input().strip().split()))
4+
def readInt():
5+
return int(raw_input())
6+
def readIntsindex0():
7+
return list(map(lambda x: int(x) - 1, input().split()))
8+
def readStrs():
9+
return raw_input().split()
10+
def readStr():
11+
return raw_input()
12+
13+
14+
for __ in range(readInt()):
15+
a = readStr()
16+
set1 = set()
17+
n = len(a)
18+
for i in range(n):
19+
if(a[i] in 'aeiou'):
20+
set1.add(a[i])
21+
sort = ''.join(sorted(set1))
22+
# print(set1)
23+
# print(sort)
24+
if(sort=='aeiou'):
25+
print(a)
26+
27+
28+
29+
'''
30+
Input:
31+
3
32+
functionality
33+
hamdard
34+
eukaryotic
35+
36+
Output:
37+
eukaryotic
38+
'''

CP/COUT-2K18/p3.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import math
2+
def readInts():
3+
return list(map(int, raw_input().strip().split()))
4+
def readInt():
5+
return int(raw_input())
6+
def readIntsindex0():
7+
return list(map(lambda x: int(x) - 1, input().split()))
8+
def readStrs():
9+
return raw_input().split()
10+
def readStr():
11+
return raw_input()
12+
13+
def primeFactors(n):
14+
a = set()
15+
while n % 2 == 0:
16+
a.add(2)
17+
n = n / 2
18+
19+
for i in range(3,int(math.sqrt(n))+1,2):
20+
# while i divides n , print i ad divide n
21+
while n % i== 0:
22+
# print i,
23+
a.add(i)
24+
n = n / i
25+
26+
if n > 2:
27+
a.add(n)
28+
return a
29+
30+
for __ in range(readInt()):
31+
n = readInt()
32+
ans = []
33+
# ans.clear()
34+
# del ans[:]
35+
ans = primeFactors(n)
36+
# print(ans)
37+
# print("Sorted version :",sorted(ans))
38+
39+
ans = list(ans)
40+
ans = sorted(ans)
41+
for i in range(len(ans)):
42+
print(ans[i]),
43+
print
44+
45+
46+
'''
47+
Input:
48+
5
49+
2
50+
3
51+
4
52+
5
53+
48
54+
Output:
55+
2
56+
3
57+
2
58+
5
59+
2 3
60+
'''

0 commit comments

Comments
 (0)