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
a3a254c
commit 570591f
Showing
7 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob1.py
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,15 @@ | ||
for __ in range(int(input())): | ||
n = int(raw_input()) | ||
# map(int, raw_input().split()) | ||
a = [0,0,0] | ||
b = [100,100,100] | ||
for i in range(n): | ||
[c,l,x] = map(int, raw_input().split()) | ||
if x>a[l-1]: | ||
a[l-1]=x | ||
b[l-1]=c | ||
elif x==a[l-1]: | ||
if b[l-1]>c: | ||
b[l-1]=c | ||
for i in xrange(3): | ||
print str(a[i])+' '+str(b[i]) |
31 changes: 31 additions & 0 deletions
31
CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob2.py
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,31 @@ | ||
for kohli in range(input()): | ||
n = int(input()) | ||
x=[] | ||
y=[] | ||
xx=[] | ||
yy=[] | ||
ans=[] | ||
for i in range(n): | ||
a,b = map(int,raw_input().split(' ')) | ||
x.append(a) | ||
y.append(b) | ||
# print(x,y) | ||
for i in range(n): | ||
yy.append([y[i],i]) | ||
# print(yy) | ||
yy.sort(key = lambda x:x[0]) | ||
# print(yy) | ||
yy = yy[::-1] | ||
# print(yy) | ||
for i in yy: | ||
if(len(ans)==3): | ||
break | ||
if(x[i[1]] in xx): | ||
continue | ||
else: | ||
xx.append(x[i[1]]) | ||
ans.append(i[0]) | ||
if(len(ans)==3): | ||
print(sum(ans)) | ||
else: | ||
print('0') |
16 changes: 16 additions & 0 deletions
16
CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob3.py
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,16 @@ | ||
# cook your code here | ||
t=int(raw_input()) | ||
for a0 in xrange(t): | ||
a,k=map(float,raw_input().split()) | ||
b=map(float,raw_input().split()) | ||
# print a,k,b | ||
m=min(b) | ||
if m<0: | ||
for i in xrange(3): | ||
b[i]+=abs(m) | ||
[x1,x2,x3]=sorted(b) | ||
if (k >= (x3-x1)/2): | ||
print float(a*a) | ||
else: | ||
if x3-x1-2*k>a: print float(0) | ||
else: print abs(x3-x1-2*k-a)*a |
89 changes: 89 additions & 0 deletions
89
CP/ACM-ICPC Asia-Gwalior Onsite Replay Contest 2017/prob4.cpp
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,89 @@ | ||
#include <bits/stdc++.h> | ||
#define F first | ||
#define S second | ||
using namespace std; | ||
|
||
typedef long long ll; | ||
typedef pair<int, int> pii; | ||
|
||
ll y[4][2010], sz[4]; | ||
|
||
ll case1(int l, int r) { | ||
ll ans = 0; | ||
int i, j; | ||
for(i = 1; i <= sz[l]; ++i) { | ||
ll cur = 0, cnt = 0; | ||
for(j = 1; j <= sz[r]; ++j) { | ||
ll z = abs(r - l)*abs(y[r][j] - y[l][i]) + 2*abs(r - l)*min(y[r][j], y[l][i]); | ||
ans += cnt*z - cur; | ||
cur += z; | ||
cnt += 1; | ||
} | ||
} | ||
return ans; | ||
} | ||
|
||
int main() { | ||
int t, i, j; | ||
// freopen("in.txt", "r", stdin); | ||
scanf("%d", &t); | ||
while(t--) { | ||
int n, u, v; | ||
scanf("%d", &n); | ||
sz[1] = sz[2] = sz[3] = 0; | ||
for(i = 1; i <= n; ++i) { | ||
scanf("%d %d", &u, &v); | ||
sz[u]++; | ||
y[u][sz[u]] = v; | ||
} | ||
for(i = 1; i <= 3; ++i) { | ||
sort(y[i] + 1, y[i] + sz[i] + 1); | ||
} | ||
ll ans = 0; | ||
//Case 1 and 2 | ||
ans += case1(1, 2); | ||
//Case 2 and 1 | ||
ans += case1(2, 1); | ||
// Case 2 and 3 | ||
ans += case1(2, 3); | ||
// Case 3 and 2 | ||
ans += case1(3, 2); | ||
// Case 1 and 3 | ||
ans += case1(1, 3); | ||
// Case 3 and 1 | ||
ans += case1(3, 1); | ||
// cout << ans << endl; | ||
// Case 1, 2 and 3 | ||
for(i = 1; i <= sz[1]; ++i) { | ||
ll cur = 0, cnt = 0, ptr = 1; | ||
for(j = 1; j <= sz[2]; ++j) { | ||
ll z = abs(y[2][j] - y[1][i]) + 2*min(y[2][j], y[1][i]); | ||
while(ptr <= sz[3] and y[3][ptr] < y[2][j] + y[2][j] - y[1][i]) ptr++; | ||
ans += (ptr - 1)*z - (sz[3] - ptr + 1)*z; | ||
// cout << "in " << ptr << endl; | ||
} | ||
} | ||
// cout << ans << endl; | ||
for(i = 1; i <= sz[3]; ++i) { | ||
ll cur = 0, cnt = 0, ptr = 1; | ||
for(j = 1; j <= sz[2]; ++j) { | ||
ll z = abs(y[2][j] - y[3][i]) + 2*min(y[2][j], y[3][i]); | ||
while(ptr <= sz[1] and y[1][ptr] < y[2][j] + y[2][j] - y[3][i]) ptr++; | ||
ans += (ptr - 1)*z - (sz[1] - ptr + 1)*z; | ||
} | ||
} | ||
// cout << ans << endl; | ||
for(i = 1; i <= sz[1]; ++i) { | ||
ll cur = 0, cnt = 0, ptr = 1; | ||
for(j = 1; j <= sz[3]; ++j) { | ||
ll z = 2*abs(y[3][j] - y[1][i]) + 2*2*min(y[3][j], y[1][i]); | ||
while(ptr <= sz[2] and y[2][ptr] + y[2][ptr] <= y[1][i] + y[3][j]) ptr++; | ||
ans += (ptr - 1)*z - (sz[2] - ptr + 1)*z; | ||
} | ||
} | ||
// cout << ans << endl; | ||
long double fin = (long double)ans/2.0; | ||
printf("%.3Lf\n", fin); | ||
} | ||
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,58 @@ | ||
for kohli in range(input()): | ||
n = int(input()) | ||
a = list(map(int, raw_input().split())) | ||
c1=0 | ||
c2=0 | ||
sum=0 | ||
for x in range(10): | ||
i=0 | ||
j=0 | ||
for i in range(len(a)): | ||
for j in range(len(a)): | ||
if(j>len(a)): | ||
break | ||
if(len(a)==1): | ||
break | ||
if(len(a)==2): | ||
sum = a[0]+a[1] | ||
if(not(sum)&1): | ||
# print(sum) | ||
# print(a) | ||
a.pop(0) | ||
a.pop(0) | ||
a.append(sum) | ||
# print(a) | ||
else: | ||
if(i!=j and i<len(a) and j<len(a)): | ||
sum = a[i]+a[j] | ||
# print(sum) | ||
if(not(sum)&1 and i!=j and i<len(a) and j<len(a)): | ||
# print(sum) | ||
# print(i,j) | ||
# print(a) | ||
if(i<j): | ||
a.pop(i) | ||
# print(a) | ||
a.pop((j-1) if (j-1)>=0 else j+len(a)-2) | ||
# print(a) | ||
else: | ||
a.pop(j) | ||
# print(a) | ||
a.pop((i-1) if (i-1)>=0 else i+len(a)-2) | ||
# print(a) | ||
a.append(sum) | ||
# print(a) | ||
if(len(a)==1): | ||
break | ||
if(i>len(a)): | ||
break | ||
if(len(a)==1): | ||
break | ||
print(len(a)) | ||
a[:] = [] | ||
|
||
''' | ||
1 | ||
5 | ||
2 1 3 1 3 | ||
''' |
Empty file.
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 @@ | ||
// Could not solve this motherf***er |