Skip to content

Commit

Permalink
March Challenge 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
harrypotter0 committed Mar 14, 2018
1 parent 3010074 commit 9f9be25
Show file tree
Hide file tree
Showing 21 changed files with 1,024 additions and 143 deletions.
82 changes: 82 additions & 0 deletions CP/ International Coding League (Rated)/p1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# International Coding League (Rated)

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 numlistTostr(list1):
return ''.join(list1)
def strlistTostr(list1):
return ''.join(str(e) for e in list1)
def strTolist(str):
return str.split()
def strlistTointlist(str):
return map(int, str)
def slicenum(number,x):
return int(str(number)[:x])
def numTobin(A):
s = str(bin(A))[2:]
s = '0'*(31-len(s)) + s
return s
def precise(num):
return "{0:.10f}".format(num)
def rsorted(a):
return sorted(a,reverse=True)

for __ in range(readInt()):
n,m = readInts()
arr,a = [],[]
for i in range(n):
arr.append(readInts())
for i in range(n):
for j in range(m):
a.append(arr[i][j])
# print(arr)
# print(a)
a= rsorted(a)
# print(a)
sum1,sum2 =0,0
for i in range(len(a)):
if(i&1):
sum2+=a[i]
else:
sum1+=a[i]
if(sum2==sum1):
print("Draw")
# print(sum1,sum2)
elif(sum2>sum1):
print("Geno")
# print(sum1,sum2)
else:
print("Cyborg")
# print(sum1,sum2)




'''
3
1 1
3
2 3
4 4 4
4 4 4
2 3
4 3 4
4 4 4

Sample Output

Cyborg
Draw
Cyborg

Geno
'''
66 changes: 66 additions & 0 deletions CP/ International Coding League (Rated)/p2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# International Coding League (Rated)
from fractions import gcd
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 numlistTostr(list1):
return ''.join(list1)
def strlistTostr(list1):
return ''.join(str(e) for e in list1)
def strTolist(str):
return str.split()
def strlistTointlist(str):
return map(int, str)
def slicenum(number,x):
return int(str(number)[:x])
def numTobin(A):
s = str(bin(A))[2:]
s = '0'*(31-len(s)) + s
return s
def precise(num):
return "{0:.10f}".format(num)
def rsorted(a):
return sorted(a,reverse=True)

for __ in range(readInt()):
n,k = readInts()
string = readStr()
con = 0
col =n
summ = 0
for i in string:
if(ord(i)-96>2*k):
con+=1
col-=1
summ+=ord(i)-96
# print(summ)
lolo = k*(col-con)+summ
p = gcd(abs(lolo),k)
lolo/=p
k/=p
print lolo,k

'''
Sample Input

2
10 6
abcdefghij
10 1
qwertyuiop

Sample Output

10 1
159 1


'''
72 changes: 72 additions & 0 deletions CP/ International Coding League (Rated)/p3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll int,ll int>
#define vi vector<ll int>
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i,a,b) for(ll int i=a;i<b;i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
const int inf =1e9;
using namespace std;
#define MAX 100005

int gcd(int a, int b) {
while(b) {
int r = a % b;
a = b;
b = r;
}
return a;
}

int main() {
ll t;
cin>>t;
while(t--)
{
ll n,m,a,b,c,d,p ;
cin>>n>>m>>a>>b>>c>>d>>p;
ll A,B,C;
A = a+b;
B = c+d;
C = p+m*b+n*d;
ll g = gcd(A,B);
if(C %g!=0){
cout<<"-1"<<endl;
continue;
}
int ans = inf;
int till = C / A;
for(int N = m; N <= till; ++N) {
int E = (C - N * A);
if (E % B != 0) {
continue;
}
E /= B;
if (E < n) {
break;
}
int S = N - m, W = E - n;
ans = min(ans, N + S + E + W);
}
if (ans == inf) {
ans = -1;
}
else {
assert(ans >= n + m);
}
cout << ans << "\n";


}

return 0;
}
55 changes: 55 additions & 0 deletions CP/ International Coding League (Rated)/p4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll int,ll int>
#define vi vector<ll int>
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i,a,b) for(ll int i=a;i<b;i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
#define N 100005

int main() {
ll t;
cin>>t;
while(t--)
{
ll n,k;
cin>>

}

return 0;
}

/*

Sample Input

5 6
1 3 4
1 2 1
1 1 4
2 4 2 3
2 4 2 1
2 3 5 3

Sample Output

4
1
3
-1
4
5


*/
56 changes: 33 additions & 23 deletions CP/ March Challenge 2018/p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,39 @@ def readStr():
return raw_input()


for __ in range(readInt()):
n,h = readInts()
a = readInts()
a = sorted(a)
print(a)
# summ = 0
# for i in range(n):
# summ+= a[i]
diff = h-n
if(n==h):
print(a[n-1])
continue
for i in range(diff):
print("yeh waala hai ", a[n+i-1])
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(a)
# di = i
print(int(a[n+i]))
for m in range(readInt()):
strings = raw_input().split(" ")
N= int(strings[0])
H= int(strings[1])
strings1=raw_input().split(" ")
A= map(int, strings1)
maxi = A[0]
sumi = 0
for i in range(len(A)):
sumi += A[i]
if(maxi < A[i]):
maxi = A[i]
flag=True
#suitable values of K
avg = sumi/H
low = avg
high = maxi
#######################################3
hr = 0
while(low<=high):
mid = (low+high)/2
hr = 0
for j in range(len(A)):
if( A[j]%mid != 0):
hr += A[j]/mid + 1
else:
hr += A[j]/mid
if(hr <= H):
ans = mid
high = mid - 1
else:
low = mid + 1
print ans


'''
Expand Down
Loading

0 comments on commit 9f9be25

Please sign in to comment.