forked from harrypotter0/algorithms-in-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49be34e
commit 0e9324f
Showing
12 changed files
with
493 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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 = readInt() | ||
a = readInts() | ||
b1 = readInts() | ||
b2 = list(reversed(b1)) | ||
# print(b1,b2) | ||
f1=0 | ||
for i in range(n): | ||
if(a[i]>b1[i]): | ||
f1=1 | ||
break | ||
f2=0 | ||
for i in range(n): | ||
if(a[i]>b2[i]): | ||
f2=1 | ||
break | ||
if(f1==0 and f2==0): | ||
print("both") | ||
elif(f1==0): | ||
print("front") | ||
elif(f2==0): | ||
print("back") | ||
else : | ||
print("none") | ||
|
||
|
||
|
||
''' | ||
Input | ||
4 | ||
3 | ||
1 2 3 | ||
2 3 4 | ||
3 | ||
1 2 1 | ||
1 2 1 | ||
3 | ||
3 2 1 | ||
1 2 3 | ||
4 | ||
1 3 2 4 | ||
1 2 3 5 | ||
Output | ||
front | ||
both | ||
back | ||
none | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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 = readInt() | ||
summ = 0 | ||
for i in range(n): | ||
arr = readInts() | ||
p = arr[0] | ||
q = arr[0]*(1.+arr[2]/100.)*(1.-arr[2]/100.) | ||
# print(p,q) | ||
profit = p-q | ||
summ+=profit*arr[1] | ||
print(summ) | ||
|
||
''' | ||
pricei, quantityi and discounti. | ||
Input: | ||
2 | ||
2 | ||
100 5 10 | ||
100 1 50 | ||
3 | ||
10 10 0 | ||
79 79 79 | ||
100 1 100 | ||
Output: | ||
30.000000000 | ||
3995.0081000 | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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 = readInt() | ||
arr = readInts() | ||
summ =0 | ||
arr = sorted(arr) | ||
# if(arr[0]==arr[n-1]): | ||
# n-=1 | ||
# print(n*(n+1)/2) | ||
# continue | ||
for i in range(n-1): | ||
if(arr[i]==arr[i+1]): | ||
summ+=1 | ||
# for i in range(n-1,0,-1): | ||
# arr = reversed(sorted(arr)) | ||
# if(arr[i]==arr[i-1]): | ||
# # print(arr[i],arr[i-1]) | ||
# s1 = 1 | ||
# for j in arr: | ||
# s1=1 | ||
# s = arr[i-1]+j | ||
# if(s not in arr and ): | ||
# summ+=s1 | ||
# arr[i-1]=s | ||
# break | ||
# else: | ||
# s1+=1 | ||
# print(s,arr) | ||
|
||
print(summ) | ||
|
||
|
||
|
||
|
||
''' | ||
Input: | ||
2 | ||
3 | ||
1 2 3 | ||
3 | ||
2 1 2 | ||
1 | ||
4 | ||
2 2 2 2 | ||
Output: | ||
0 | ||
1 | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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() | ||
|
||
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] | ||
if(n==h): | ||
print(arr[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) | ||
break | ||
# # print("loda") | ||
|
||
|
||
''' | ||
Input: | ||
1 | ||
4 5 | ||
4 3 2 100 | ||
Output: | ||
3 | ||
2 | ||
4 | ||
''' |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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,k= readInts() | ||
arr = readInts() | ||
arr = sorted(arr) | ||
diff = k-arr[0] | ||
if(diff>0): | ||
print(k-arr[0]) | ||
else: | ||
print("0") | ||
|
||
|
||
|
||
|
||
|
||
|
||
''' | ||
Sample Input 0 | ||
3 | ||
5 3 | ||
1 2 3 4 5 | ||
6 9 | ||
1 1 1 1 1 1 | ||
3 -1 | ||
1 2 4 | ||
Sample Output 0 | ||
2 | ||
8 | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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().split() | ||
|
||
|
||
for __ in range(readInt()): | ||
a,b = readStr() | ||
# a = list(a) | ||
# print(a) | ||
# for i in range(len(a)) : | ||
# print(a[i]) | ||
|
||
a = map(int,str(a)) | ||
mini = min(int(b),len(a)) | ||
|
||
# print(mini) | ||
# print(a) | ||
i=0 | ||
while i < min(mini,len(a)): | ||
if(a[i]==9 ): | ||
mini+=1 | ||
a[i]=9 | ||
# print(mini) | ||
i+=1 | ||
# print(a) | ||
|
||
|
||
str1 = ''.join(str(e) for e in a) | ||
print(str1) | ||
|
||
''' | ||
3 | ||
961468737763377902 4 | ||
577894577902683672 1 | ||
474923610533896544 9 | ||
3 | ||
923 23 | ||
234 12 | ||
32 12 | ||
3 | ||
000000099999999999 10 | ||
577894577902683672 1 | ||
474923610533896544 9 | ||
''' |
Oops, something went wrong.