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
daeb80a
commit 07c0d4d
Showing
5 changed files
with
150 additions
and
0 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,23 @@ | ||
# cook your code here | ||
a = [] | ||
n = 10**6+10**5 | ||
prime = [True for i in range(n+1)] | ||
p = 2 | ||
while (p * p <= n): | ||
# If prime[p] is not changed, then it is a prime | ||
if (prime[p] == True): | ||
|
||
# Update all multiples of p | ||
for i in range(p * 2, n+1, p): | ||
prime[i] = False | ||
p += 1 | ||
# Print all prime numbers | ||
for p in range(2, n): | ||
if prime[p]: | ||
a.append(p+1) | ||
# print(a) | ||
|
||
for kohli in range(int(raw_input())): | ||
n = int(raw_input()) | ||
# print(a) | ||
print(a[n]*-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,21 @@ | ||
for _ in range(input()): | ||
arr=list(raw_input()) | ||
string='' | ||
for i in arr: | ||
if ord('A')<=ord(i)<=ord('D'): | ||
string+='A' | ||
elif ord('E')<=ord(i)<=ord('H'): | ||
string+='H' | ||
elif ord('I')<=ord(i)<=ord('K'): | ||
string+='I' | ||
elif ord('L')<=ord(i)<=ord('N'): | ||
string+="M" | ||
elif ord("O")<=ord(i)<=ord("Q"): | ||
string+="O" | ||
elif ord("R")<=ord(i)<=ord("T"): | ||
string+="T" | ||
elif i=="U" or i=="V" or i=="W" or i=="X" or i=="Y": | ||
string+=i | ||
elif i=="Z": | ||
string+="A" | ||
print string |
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,32 @@ | ||
for kohli in range(input()): | ||
a = raw_input() | ||
b = raw_input() | ||
n = len(a) | ||
m = len(b) | ||
t = m//n | ||
# print "aage baddd " | ||
# print a,b,n,m | ||
# print "aage baddd ",t | ||
for i in range(t): | ||
if(b.find(a)!=-1): | ||
b = b.replace(a,'') | ||
# print b | ||
# print b | ||
if(b==''): | ||
print "YES" | ||
else: | ||
print "NO" | ||
|
||
''' | ||
4 | ||
ab | ||
abab | ||
ab | ||
aabb | ||
ab | ||
aba | ||
abc | ||
aabcbcabc | ||
''' |
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,74 @@ | ||
''' | ||
1 | ||
5 5 | ||
0 0 0 -1 5 | ||
0 0 0 -1 0 | ||
1 0 0 0 0 | ||
0 0 0 0 0 | ||
0 0 0 0 0 | ||
''' | ||
|
||
for _ in range(int(raw_input())): | ||
n,m = map(int,raw_input().split()) | ||
ar = [] | ||
mx = 0 | ||
for i in range(n): | ||
ar.append(map(int,raw_input().split())) | ||
# print(ar) | ||
# print(max(ar[-1])) | ||
mx = max(max(ar[-1]),mx ) | ||
# print(mx) | ||
|
||
vis=[] | ||
for i in range(n): | ||
vis.append([0]*m) | ||
# print(vis) | ||
|
||
v=[] | ||
for i in range(mx+1): | ||
v.append([]) | ||
# print(v) | ||
|
||
for i in range(n): | ||
for j in range(m): | ||
if ar[i][j] > 0: | ||
v[ar[i][j]].append((i,j)) | ||
# print v | ||
|
||
for i in range(mx,0,-1): | ||
for cx,cy in v[i]: | ||
# print cx,cy | ||
if vis[cx][cy] == 2: | ||
continue | ||
if cx+1 < n and ar[cx+1][cy]!=-1 and vis[cx+1][cy]==0: | ||
vis[cx+1][cy] = 1 | ||
v[i-1].append((cx+1,cy)) | ||
if cx-1 > -1 and ar[cx-1][cy]!=-1 and vis[cx-1][cy]==0: | ||
vis[cx-1][cy] = 1 | ||
v[i-1].append((cx-1,cy)) | ||
if cy+1 < m and ar[cx][cy+1]!=-1 and vis[cx][cy+1]==0: | ||
vis[cx][cy+1] = 1 | ||
v[i-1].append((cx,cy+1)) | ||
if cy-1 > -1 and ar[cx][cy-1]!=-1 and vis[cx][cy-1]==0: | ||
vis[cx][cy-1] = 1 | ||
v[i-1].append((cx,cy-1)) | ||
vis[cx][cy] = 2 | ||
# print vis | ||
# for __ in vis: | ||
# print(__) | ||
# print "fuck me mother-fucker" | ||
# print v | ||
# print v | ||
|
||
for i in range(n): | ||
st = '' | ||
for j in range(m): | ||
if ar[i][j] ==-1: | ||
st += 'B' | ||
elif vis[i][j]>0: | ||
st+='Y' | ||
else: | ||
st+='N' | ||
print st |
Empty file.