From 07c0d4d5843a55afee1f929a6ee5ef7bcfb33737 Mon Sep 17 00:00:00 2001 From: harrypotter0 <9654263057akashkandpal@gmail.com> Date: Mon, 29 Jan 2018 01:14:50 +0530 Subject: [PATCH] AlgoFlux Online Qualifier --- CP/AlgoFlux Online Qualifier/prob1.py | 23 +++++++++ CP/AlgoFlux Online Qualifier/prob2.py | 21 ++++++++ CP/AlgoFlux Online Qualifier/prob3.py | 32 ++++++++++++ CP/January Lunchtime 2018/prob2.py | 74 +++++++++++++++++++++++++++ CP/January Lunchtime 2018/prob3.cpp | 0 5 files changed, 150 insertions(+) create mode 100644 CP/AlgoFlux Online Qualifier/prob1.py create mode 100644 CP/AlgoFlux Online Qualifier/prob2.py create mode 100644 CP/AlgoFlux Online Qualifier/prob3.py create mode 100644 CP/January Lunchtime 2018/prob3.cpp diff --git a/CP/AlgoFlux Online Qualifier/prob1.py b/CP/AlgoFlux Online Qualifier/prob1.py new file mode 100644 index 0000000..239bfcc --- /dev/null +++ b/CP/AlgoFlux Online Qualifier/prob1.py @@ -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) diff --git a/CP/AlgoFlux Online Qualifier/prob2.py b/CP/AlgoFlux Online Qualifier/prob2.py new file mode 100644 index 0000000..608fe9e --- /dev/null +++ b/CP/AlgoFlux Online Qualifier/prob2.py @@ -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 diff --git a/CP/AlgoFlux Online Qualifier/prob3.py b/CP/AlgoFlux Online Qualifier/prob3.py new file mode 100644 index 0000000..ca630d4 --- /dev/null +++ b/CP/AlgoFlux Online Qualifier/prob3.py @@ -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 + +''' diff --git a/CP/January Lunchtime 2018/prob2.py b/CP/January Lunchtime 2018/prob2.py index e69de29..938b601 100644 --- a/CP/January Lunchtime 2018/prob2.py +++ b/CP/January Lunchtime 2018/prob2.py @@ -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 diff --git a/CP/January Lunchtime 2018/prob3.cpp b/CP/January Lunchtime 2018/prob3.cpp new file mode 100644 index 0000000..e69de29