Skip to content

Commit 0f8a520

Browse files
committed
Turing Cup Qualifier 2
1 parent aea869a commit 0f8a520

File tree

6 files changed

+258
-65
lines changed

6 files changed

+258
-65
lines changed

CP/Cook-a-Code/p2.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,32 @@ def readStr():
1212

1313

1414
for __ in range(readInt()):
15+
a,b = readInts()
1516
arr = readInts()
17+
brr = readInts()
18+
win = 0 if(a>b) else: 1
19+
print(winner)
20+
c= [0 ,0]
21+
for i in range(len(arr)):
22+
if(arr[i]&1):
23+
c[0]+=1
24+
for i in range(len(brr)):
25+
if(brr[i]&1):
26+
c[1]+=1
27+
print(c[0],c[1])
28+
if(c[win]>=c[(win+1)%2]):
29+
print("alan")
30+
else:
31+
print("chef")
32+
33+
34+
35+
'''
36+
Input:
37+
1
38+
3 2
39+
1 2 3 8 9 10 11 4 5 6 7
40+
21 31 43 52 11 36 22 11 23 17 8
41+
Output:
42+
chef
43+
'''

CP/Turing Cup Qualifier 2/p1.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import math
2+
def readInts():
3+
return list(map(int, raw_input().strip().split()))
4+
def readInt():
5+
return int(raw_input())
6+
def readIntsindex0():
7+
return list(map(lambda x: int(x) - 1, input().split()))
8+
def readStrs():
9+
return raw_input().split()
10+
def readStr():
11+
return raw_input()
12+
13+
14+
for __ in range(readInt()):
15+
a,b = readInts()
16+
arr = readInts()
17+
brr = readInts()
18+
if(a>b):
19+
win = 0
20+
else:
21+
win = 1
22+
# win = if(a>b):0 else:1
23+
# print(win)
24+
c= [0 ,0]
25+
for i in range(len(arr)):
26+
if(arr[i]&1):
27+
c[0]+=1
28+
for i in range(len(brr)):
29+
if(brr[i]&1):
30+
c[1]+=1
31+
# print(c[0],c[1])
32+
if(c[win]>=c[(win+1)%2]):
33+
print("alan")
34+
else:
35+
print("chef")
36+
37+
38+
39+
'''
40+
Input:
41+
1
42+
3 2
43+
1 2 3 8 9 10 11 4 5 6 7
44+
21 31 43 52 11 36 22 11 23 17 8
45+
Output:
46+
chef
47+
'''

CP/Turing Cup Qualifier 2/p2.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import math
2+
def readInts():
3+
return list(map(int, raw_input().strip().split()))
4+
def readInt():
5+
return int(raw_input())
6+
def readIntsindex0():
7+
return list(map(lambda x: int(x) - 1, input().split()))
8+
def readStrs():
9+
return raw_input().split()
10+
def readStr():
11+
return raw_input()
12+
13+
14+
for i in range(readInt()):
15+
d = {}
16+
n = readInt()
17+
for x in range(n):
18+
line = readStrs()
19+
if line[2] in d:
20+
d[line[2]].append(line[1])
21+
else:
22+
d[line[2]] = [line[1]]
23+
# print(d)
24+
25+
res = 0
26+
v=d.values()
27+
# print v
28+
for y in v:
29+
if(len(y))>1:
30+
res += len(set(y))
31+
if res==0:
32+
print '-1'
33+
else:
34+
print res
35+
36+
37+
'''
38+
Input:
39+
3
40+
3
41+
1400203032 nerdyninja 4e4d6c332b6fe62a63afe56171fd3725
42+
1400233032 adikul30 7320eede6fd68c1d7a28506efbf593e7
43+
1400201232 nerdyninja 4e4d6c332b6fe62a63afe56171fd3725
44+
3
45+
1400203032 nerdyninja 4e4d6c332b6fe62a63afe56171fd3725
46+
1400233032 nerdyninja 7320eede6fd68c1d7a28506efbf593e7
47+
1400201232 adikul30 4e4d6c332b6fe62a63afe56171fd3725
48+
2
49+
1400203032 nerdyninja 4e4d6c332b6fe62a63afe56171fd3725
50+
1400201232 adikul30 7320eede6fd68c1d7a28506efbf593e7
51+
52+
Output:
53+
1
54+
2
55+
-1
56+
57+
'''

CP/Turing Cup Qualifier 2/p3.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import math
2+
def readInts():
3+
return list(map(int, raw_input().strip().split()))
4+
def readInt():
5+
return int(raw_input())
6+
def readIntsindex0():
7+
return list(map(lambda x: int(x) - 1, input().split()))
8+
def readStrs():
9+
return raw_input().split()
10+
def readStr():
11+
return raw_input()
12+
13+
14+
for __ in range(readInt()):
15+
m,n = readInts()
16+
a = readInts()
17+
c = 0
18+
for i in range(n-1):
19+
c= c+1
20+
c=c-min(c,a[i+1]-a[i]-1)
21+
c=c+1
22+
c=c-min(c,m-a[-1])
23+
if c==0:
24+
print 1
25+
else:
26+
print c
27+
28+
29+
'''
30+
Input:
31+
2
32+
5 5
33+
1 2 3 4 5
34+
5 2
35+
1 3
36+
Output:
37+
5
38+
1
39+
'''

CP/Turing Cup Qualifier 2/p4.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define mp(a,b) make_pair(a,b)
4+
#define ff first
5+
#define setp setprecision(4)<<fixed
6+
#define ss second
7+
#define fori(v) for(int i=0; i<v; i++)
8+
#define forj(v) for(int j=0; j<v; j++)
9+
#define fork(v) for(int k=0; k<v; k++)
10+
#define forl(v) for(int l=0; l<v; l++)
11+
#define fort(v) for(int t=0; t<v; t++)
12+
#define forz(v) for(int z=0; z<v; z++)
13+
#define lli long long int
14+
#define MAX 1100
15+
#define double long double
16+
#define ch 400
17+
int inf = pow(10,9);
18+
lli modulo = pow(10,9)+7;
19+
lli md = pow(10,9)+7;
20+
double eps = 1e-13;
21+
ifstream in;
22+
ofstream out;
23+
//#define cin in
24+
//#define cout out
25+
void deal(){
26+
int t;
27+
cin>>t;
28+
forl(t){
29+
int n;
30+
cin>>n;
31+
int arr[n];
32+
lli sum = 0;
33+
fori(n){
34+
cin>>arr[i];
35+
sum+=arr[i];
36+
for(int j=i-1; j>-1; j--){
37+
int mn = min(arr[i],arr[j]);
38+
if(mn<=(arr[i]&arr[j]))
39+
sum+=mn;
40+
}
41+
}
42+
cout<<sum<<'\n';
43+
}
44+
}
45+
int main() {
46+
deal();
47+
}

CP/templates/temp.cpp

Lines changed: 40 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,47 @@
11
#include <bits/stdc++.h>
22
using namespace std;
3-
4-
#define ll long long
5-
6-
const int N = 2e3 + 5;
7-
8-
ll cnt[5], sum[5];
9-
vector<int> a[5];
10-
ll pre[N];
11-
12-
void solve() {
13-
14-
for(int i = 0; i < 3; i++) {
15-
a[i].clear();
16-
cnt[i] = 0;
17-
sum[i] = 0;
18-
}
19-
20-
int n, x, y;
21-
22-
scanf("%d", &n);
23-
for(int i = 1; i <= n; i++) {
24-
scanf("%d %d", &x, &y);
25-
x--, y--;
26-
a[x].push_back(y);
27-
sum[x] += y;
28-
cnt[x]++;
29-
}
30-
31-
ll ans = 0;
32-
33-
for(int i = 0; i < 3; i++) {
34-
sort(a[i].begin(), a[i].end());
35-
}
36-
37-
for(int i = 0; i < 3; i++) {
38-
for(int j = 0; j < 3; j++) {
39-
if(i == j) continue;
40-
for(int k = 0; k < a[i].size(); k++) {
41-
for(int p = k + 1; p < a[i].size(); p++) {
42-
ans += a[j].size() * 1LL * abs((a[i][p] - a[i][k]) * 1LL * (i - j));
43-
}
3+
#define mp(a,b) make_pair(a,b)
4+
#define ff first
5+
#define setp setprecision(4)<<fixed
6+
#define ss second
7+
#define fori(v) for(int i=0; i<v; i++)
8+
#define forj(v) for(int j=0; j<v; j++)
9+
#define fork(v) for(int k=0; k<v; k++)
10+
#define forl(v) for(int l=0; l<v; l++)
11+
#define fort(v) for(int t=0; t<v; t++)
12+
#define forz(v) for(int z=0; z<v; z++)
13+
#define lli long long int
14+
#define MAX 1100
15+
#define double long double
16+
#define ch 400
17+
int inf = pow(10,9);
18+
lli modulo = pow(10,9)+7;
19+
lli md = pow(10,9)+7;
20+
double eps = 1e-13;
21+
ifstream in;
22+
ofstream out;
23+
//#define cin in
24+
//#define cout out
25+
void deal(){
26+
int t;
27+
cin>>t;
28+
forl(t){
29+
int n;
30+
cin>>n;
31+
int arr[n];
32+
lli sum = 0;
33+
fori(n){
34+
cin>>arr[i];
35+
sum+=arr[i];
36+
for(int j=i-1; j>-1; j--){
37+
int mn = min(arr[i],arr[j]);
38+
if(mn<=(arr[i]&arr[j]))
39+
sum+=mn;
4440
}
4541
}
42+
cout<<sum<<'\n';
4643
}
47-
48-
pre[0] = 0;
49-
for(int i = 0; i < a[1].size(); i++) {
50-
pre[i + 1] = pre[i] + a[1][i];
51-
}
52-
53-
for(int i = 0; i < a[0].size(); i++) {
54-
int start = 0;
55-
for(int j = 0; j < a[2].size(); j++) {
56-
ll tot = a[0][i] + a[2][j];
57-
while(start < cnt[1] && 2*a[1][start] < tot) start++;
58-
ll contri = ((tot * start) - (2LL * pre[start])) + ((2LL * (pre[cnt[1]] - pre[start])) - (tot * (cnt[1] - start)));
59-
ans += contri;
60-
}
61-
}
62-
double res = double(ans) / 2.0;
63-
cout<<setprecision(7)<<fixed<<res<<'\n';
6444
}
65-
6645
int main() {
67-
int t;
68-
scanf("%d", &t);
69-
while(t--) {
70-
solve();
71-
}
72-
}
46+
deal();
47+
}

0 commit comments

Comments
 (0)