Skip to content

Commit

Permalink
COUT-2K18
Browse files Browse the repository at this point in the history
  • Loading branch information
harrypotter0 committed Mar 11, 2018
1 parent 0e9324f commit aea869a
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 46 deletions.
91 changes: 45 additions & 46 deletions CP/ March Challenge 2018/p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,30 @@ def readIntsindex0():
def readStr():
return raw_input()

def binarySearch (arr, l, r, x):

# Check base case
if r >= l:

mid = l + (r - l)/2

# If element is present at the middle itself
if arr[mid] == x:
return mid

# If element is smaller than mid, then it
# can only be present in left subarray
elif arr[mid] > x:
return binarySearch(arr, l, mid-1, x)

# Else the element can only be present
# in right subarray
else:
return binarySearch(arr, mid+1, r, x)

else:
# Element is not present in the array
return -1

for __ in range(readInt()):
n,h = readInts()
arr = readInts()
summ = 0
for i in arr:
summ+=i
arr = sorted(arr)
summ = float(summ)
minn = int(math.ceil(summ/h))
maxn = arr[n-1]
a = readInts()
a = sorted(a)
print(a)
# summ = 0
# for i in range(n):
# summ+= a[i]
diff = h-n
if(n==h):
print(arr[n-1])
print(a[n-1])
continue
# print(minn)
for i in range(minn,maxn+1):
s=0
for j in reversed(arr):
if(j > i):
s+=(int(math.ceil(j/i))-1)
else:
break
if(n+s<=h):
print(i)
for i in range(diff):
print("yeh waala hai ", a[n+i-1])
if(a[n+i-1]/2<=1):
break
# # print("loda")
j = a[n+i-1]/2
a[n+i-1] -= j
a.append(j)
a = sorted(a)
print(a)
# di = i
print(int(a[n+i]))


'''
Expand All @@ -67,9 +41,34 @@ def binarySearch (arr, l, r, x):
4 5
4 3 2 100
Output:
1
4 6
4 3 2 100
1
7 15
1 1 1 1 1 1 1
1
5 12
232 43 213 2431 431
1
4 5
4 3 2 7
3
3 3
1 2 3
3 4
1 2 3
4 5
4 3 2 7
2
4
6 9
12 35 45 34 32 213
4 5
4 3 2 7
'''
66 changes: 66 additions & 0 deletions CP/ March Challenge 2018/p41.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import math
def readInts():
return list(map(int, raw_input().strip().split()))
def readInt():
return int(raw_input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStr():
return raw_input()

for __ in range(readInt()):
n,h = readInts()
a = readInts()
a = sorted(a)
diff = h-n
if(n==h):
print(a[n-1])
continue
for i in range(diff):
if(a[n+i-1]/2<=1):
break
j = a[n+i-1]/2
a[n+i-1] -= j
a.append(j)
a = sorted(a)
print(int(a[n+i]))


'''
Input:
1
4 5
4 3 2 100
1
4 6
4 3 2 100
1
7 15
1 1 1 1 1 1 1
1
5 12
232 43 213 2431 431
1
4 5
4 3 2 7
3
3 3
1 2 3
3 4
1 2 3
4 5
4 3 2 7
2
6 9
12 35 45 34 32 213
4 5
4 3 2 7
'''
34 changes: 34 additions & 0 deletions CP/ March Challenge 2018/p5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import math
def readInts():
return list(map(int, raw_input().strip().split()))
def readInt():
return int(raw_input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStrs():
return raw_input().split()
def readStr():
return raw_input()

for __ in range(readInt()):





'''
Input:
5 3
20 11 18 2 13
1 3
3 5
2 4
Output:
2147483629
2147483645
2147483645
'''
49 changes: 49 additions & 0 deletions CP/COUT-2K18/p1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import math
def readInts():
return list(map(int, raw_input().strip().split()))
def readInt():
return int(raw_input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStrs():
return raw_input().split()
def readStr():
return raw_input()


for __ in range(readInt()):
a = readStr()
n = len(a)
vowels,cons =0,0
for i in range(n):
if(a[i] in 'aeiou'):
vowels+=1
elif(a[i] in 'bcdfghjklmnpqrstvwxyz'):
cons+=1
print vowels,cons

# a = 'a'
# vowels =''
# cons = ''
# for i in range(26):
# if(chr(ord(a)+i) in 'aeiou'):
# vowels += chr(ord(a)+i)
# else:
# cons += chr(ord(a)+i)
# print(vowels)
# print(cons)

'''
Input
3
abcde ewa
aioue
Aefdd
Output
2 3
5 0
'''
38 changes: 38 additions & 0 deletions CP/COUT-2K18/p2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import math
def readInts():
return list(map(int, raw_input().strip().split()))
def readInt():
return int(raw_input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStrs():
return raw_input().split()
def readStr():
return raw_input()


for __ in range(readInt()):
a = readStr()
set1 = set()
n = len(a)
for i in range(n):
if(a[i] in 'aeiou'):
set1.add(a[i])
sort = ''.join(sorted(set1))
# print(set1)
# print(sort)
if(sort=='aeiou'):
print(a)



'''
Input:
3
functionality
hamdard
eukaryotic
Output:
eukaryotic
'''
60 changes: 60 additions & 0 deletions CP/COUT-2K18/p3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import math
def readInts():
return list(map(int, raw_input().strip().split()))
def readInt():
return int(raw_input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStrs():
return raw_input().split()
def readStr():
return raw_input()

def primeFactors(n):
a = set()
while n % 2 == 0:
a.add(2)
n = n / 2

for i in range(3,int(math.sqrt(n))+1,2):
# while i divides n , print i ad divide n
while n % i== 0:
# print i,
a.add(i)
n = n / i

if n > 2:
a.add(n)
return a

for __ in range(readInt()):
n = readInt()
ans = []
# ans.clear()
# del ans[:]
ans = primeFactors(n)
# print(ans)
# print("Sorted version :",sorted(ans))

ans = list(ans)
ans = sorted(ans)
for i in range(len(ans)):
print(ans[i]),
print


'''
Input:
5
2
3
4
5
48
Output:
2
3
2
5
2 3
'''
Loading

0 comments on commit aea869a

Please sign in to comment.