From 0e9324f91a6c95906c12fe3442f46b9ebd5938ed Mon Sep 17 00:00:00 2001 From: harrypotter0 <9654263057akashkandpal@gmail.com> Date: Fri, 9 Mar 2018 06:20:54 +0530 Subject: [PATCH] Hacktivate 2018 --- CP/ March Challenge 2018/p1.py | 61 +++++++++++++++++++++++++++ CP/ March Challenge 2018/p2.py | 43 +++++++++++++++++++ CP/ March Challenge 2018/p3.py | 63 ++++++++++++++++++++++++++++ CP/ March Challenge 2018/p4.py | 75 ++++++++++++++++++++++++++++++++++ CP/000-Templates/temp.cpp | 31 -------------- CP/000-Templates/temp.py | 0 CP/Hacktivate/p1.py | 40 ++++++++++++++++++ CP/Hacktivate/p2.py | 57 ++++++++++++++++++++++++++ CP/Hacktivate/p3.py | 34 +++++++++++++++ CP/Hacktivate/p4.cpp | 62 ++++++++++++++++++++++++++++ CP/Hacktivate/p5.py | 55 +++++++++++++++++++++++++ CP/templates/temp.py | 3 ++ 12 files changed, 493 insertions(+), 31 deletions(-) create mode 100644 CP/ March Challenge 2018/p1.py create mode 100644 CP/ March Challenge 2018/p2.py create mode 100644 CP/ March Challenge 2018/p3.py create mode 100644 CP/ March Challenge 2018/p4.py delete mode 100644 CP/000-Templates/temp.cpp delete mode 100644 CP/000-Templates/temp.py create mode 100644 CP/Hacktivate/p1.py create mode 100644 CP/Hacktivate/p2.py create mode 100644 CP/Hacktivate/p3.py create mode 100644 CP/Hacktivate/p4.cpp create mode 100644 CP/Hacktivate/p5.py diff --git a/CP/ March Challenge 2018/p1.py b/CP/ March Challenge 2018/p1.py new file mode 100644 index 0000000..be54790 --- /dev/null +++ b/CP/ March Challenge 2018/p1.py @@ -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 + +''' diff --git a/CP/ March Challenge 2018/p2.py b/CP/ March Challenge 2018/p2.py new file mode 100644 index 0000000..ea95e43 --- /dev/null +++ b/CP/ March Challenge 2018/p2.py @@ -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 + +''' diff --git a/CP/ March Challenge 2018/p3.py b/CP/ March Challenge 2018/p3.py new file mode 100644 index 0000000..1dbd9b1 --- /dev/null +++ b/CP/ March Challenge 2018/p3.py @@ -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 + +''' diff --git a/CP/ March Challenge 2018/p4.py b/CP/ March Challenge 2018/p4.py new file mode 100644 index 0000000..e43381e --- /dev/null +++ b/CP/ March Challenge 2018/p4.py @@ -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 + +''' diff --git a/CP/000-Templates/temp.cpp b/CP/000-Templates/temp.cpp deleted file mode 100644 index e6947d8..0000000 --- a/CP/000-Templates/temp.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -// #ifdef DEMETRIO -// #define deb(...) fprintf(stderr,__VA_ARGS__) -// #define deb1(x) cerr << #x << " = " << x << endl -// #else -// #define deb(...) 0 -// #define deb1(x) 0 -// #endif -#define pb push_back -#define mp make_pair -#define fst first -#define snd second -#define fore(i,a,b) for(int i=a,ThxDem=b;i0): + 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 +''' diff --git a/CP/Hacktivate/p2.py b/CP/Hacktivate/p2.py new file mode 100644 index 0000000..9d99381 --- /dev/null +++ b/CP/Hacktivate/p2.py @@ -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 + + +''' diff --git a/CP/Hacktivate/p3.py b/CP/Hacktivate/p3.py new file mode 100644 index 0000000..3d211ba --- /dev/null +++ b/CP/Hacktivate/p3.py @@ -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() + +a = readStr() +n = len(a) +c=0 +a = list(a) +for i in range(n/2): + if(a[i]==a[n-i-1]): + continue + elif(a[i] +using namespace std; + +const int MAX = 200005; + +// prefix[i] is going to store count of primes +// till i (including i). +int prefix[MAX + 1]; + +void buildPrefix() +{ + // Create a boolean array "prime[0..n]". A + // value in prime[i] will finally be false + // if i is Not a prime, else true. + bool prime[MAX + 1]; + memset(prime, true, sizeof(prime)); + + for (int p = 2; p * p <= MAX; p++) { + + // If prime[p] is not changed, then + // it is a prime + if (prime[p] == true) { + + // Update all multiples of p + for (int i = p * 2; i <= MAX; i += p) + prime[i] = false; + } + } + + // Build prefix array + prefix[0] = prefix[1] = 0; + for (int p = 2; p <= MAX; p++) { + prefix[p] = prefix[p - 1]; + if (prime[p]) + prefix[p]++; + } +} + +// Returns count of primes in range from L to +// R (both inclusive). +int query(int L, int R) +{ + return prefix[R] - prefix[L - 1]; +} + +// Driver code +int main() +{ + buildPrefix(); + int t; + int L,R; + cin>>t; + while(t--){ + cin>>L>>R; + cout << query(L, R) << endl; + } + + + return 0; +} diff --git a/CP/Hacktivate/p5.py b/CP/Hacktivate/p5.py new file mode 100644 index 0000000..2f92ca5 --- /dev/null +++ b/CP/Hacktivate/p5.py @@ -0,0 +1,55 @@ +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() + +a = [[1 for i in xrange(n+1)] for n in xrange(102)] + +for i in xrange(1, 101): + for j in xrange(1, i+1): + a[i+1][j] = a[i][j-1] + a[i][j] + +p = math.pow(10,9)+9 +# print(p) +for _ in xrange(int(raw_input())): + n, g = map(int, raw_input().split()) + s = 0 + ans = [n for _ in xrange(g+1)] + for i in xrange(1, g+1): + ans[i] = (pow(n+1, i+1)) - 1 + for j in range(2, i+2): + ans[i] -= ((a[i+1][j]*ans[i+1-j])) + ans[i] = (ans[i]/(i+1)) + print (int((ans[g]-1-pow(n,g)) % p)) + + + +''' +Sample Input 0 + +1 +4 2 +Sample Output 0 + +13 +Explanation 0 +(4-1)2 + (4-2)2 = 32 + 22 = 13. + +Sample Input 1 + +1 +4 3 +Sample Output 1 + +35 +Explanation 1 + +(4-1)3 + (4-2)3 = 33 + 23 = 35 +''' diff --git a/CP/templates/temp.py b/CP/templates/temp.py index 8c4355e..94b640a 100644 --- a/CP/templates/temp.py +++ b/CP/templates/temp.py @@ -5,8 +5,11 @@ 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()): arr = readInts()