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
3010074
commit 9f9be25
Showing
21 changed files
with
1,024 additions
and
143 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,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 | ||
''' |
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,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 | ||
|
||
|
||
''' |
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,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; | ||
} |
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,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 | ||
|
||
|
||
*/ |
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
Oops, something went wrong.