Skip to content

Commit

Permalink
Turing Cup Qualifier 2
Browse files Browse the repository at this point in the history
  • Loading branch information
harrypotter0 committed Mar 11, 2018
1 parent aea869a commit 0f8a520
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 65 deletions.
28 changes: 28 additions & 0 deletions CP/Cook-a-Code/p2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,32 @@ def readStr():


for __ in range(readInt()):
a,b = readInts()
arr = readInts()
brr = readInts()
win = 0 if(a>b) else: 1
print(winner)
c= [0 ,0]
for i in range(len(arr)):
if(arr[i]&1):
c[0]+=1
for i in range(len(brr)):
if(brr[i]&1):
c[1]+=1
print(c[0],c[1])
if(c[win]>=c[(win+1)%2]):
print("alan")
else:
print("chef")



'''
Input:
1
3 2
1 2 3 8 9 10 11 4 5 6 7
21 31 43 52 11 36 22 11 23 17 8
Output:
chef
'''
47 changes: 47 additions & 0 deletions CP/Turing Cup Qualifier 2/p1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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()


for __ in range(readInt()):
a,b = readInts()
arr = readInts()
brr = readInts()
if(a>b):
win = 0
else:
win = 1
# win = if(a>b):0 else:1
# print(win)
c= [0 ,0]
for i in range(len(arr)):
if(arr[i]&1):
c[0]+=1
for i in range(len(brr)):
if(brr[i]&1):
c[1]+=1
# print(c[0],c[1])
if(c[win]>=c[(win+1)%2]):
print("alan")
else:
print("chef")



'''
Input:
1
3 2
1 2 3 8 9 10 11 4 5 6 7
21 31 43 52 11 36 22 11 23 17 8
Output:
chef
'''
57 changes: 57 additions & 0 deletions CP/Turing Cup Qualifier 2/p2.py
Original file line number Diff line number Diff line change
@@ -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 readStrs():
return raw_input().split()
def readStr():
return raw_input()


for i in range(readInt()):
d = {}
n = readInt()
for x in range(n):
line = readStrs()
if line[2] in d:
d[line[2]].append(line[1])
else:
d[line[2]] = [line[1]]
# print(d)

res = 0
v=d.values()
# print v
for y in v:
if(len(y))>1:
res += len(set(y))
if res==0:
print '-1'
else:
print res


'''
Input:
3
3
1400203032 nerdyninja 4e4d6c332b6fe62a63afe56171fd3725
1400233032 adikul30 7320eede6fd68c1d7a28506efbf593e7
1400201232 nerdyninja 4e4d6c332b6fe62a63afe56171fd3725
3
1400203032 nerdyninja 4e4d6c332b6fe62a63afe56171fd3725
1400233032 nerdyninja 7320eede6fd68c1d7a28506efbf593e7
1400201232 adikul30 4e4d6c332b6fe62a63afe56171fd3725
2
1400203032 nerdyninja 4e4d6c332b6fe62a63afe56171fd3725
1400201232 adikul30 7320eede6fd68c1d7a28506efbf593e7
Output:
1
2
-1
'''
39 changes: 39 additions & 0 deletions CP/Turing Cup Qualifier 2/p3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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()


for __ in range(readInt()):
m,n = readInts()
a = readInts()
c = 0
for i in range(n-1):
c= c+1
c=c-min(c,a[i+1]-a[i]-1)
c=c+1
c=c-min(c,m-a[-1])
if c==0:
print 1
else:
print c


'''
Input:
2
5 5
1 2 3 4 5
5 2
1 3
Output:
5
1
'''
47 changes: 47 additions & 0 deletions CP/Turing Cup Qualifier 2/p4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp setprecision(4)<<fixed
#define ss second
#define fori(v) for(int i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define lli long long int
#define MAX 1100
#define double long double
#define ch 400
int inf = pow(10,9);
lli modulo = pow(10,9)+7;
lli md = pow(10,9)+7;
double eps = 1e-13;
ifstream in;
ofstream out;
//#define cin in
//#define cout out
void deal(){
int t;
cin>>t;
forl(t){
int n;
cin>>n;
int arr[n];
lli sum = 0;
fori(n){
cin>>arr[i];
sum+=arr[i];
for(int j=i-1; j>-1; j--){
int mn = min(arr[i],arr[j]);
if(mn<=(arr[i]&arr[j]))
sum+=mn;
}
}
cout<<sum<<'\n';
}
}
int main() {
deal();
}
105 changes: 40 additions & 65 deletions CP/templates/temp.cpp
Original file line number Diff line number Diff line change
@@ -1,72 +1,47 @@
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int N = 2e3 + 5;

ll cnt[5], sum[5];
vector<int> a[5];
ll pre[N];

void solve() {

for(int i = 0; i < 3; i++) {
a[i].clear();
cnt[i] = 0;
sum[i] = 0;
}

int n, x, y;

scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d %d", &x, &y);
x--, y--;
a[x].push_back(y);
sum[x] += y;
cnt[x]++;
}

ll ans = 0;

for(int i = 0; i < 3; i++) {
sort(a[i].begin(), a[i].end());
}

for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
if(i == j) continue;
for(int k = 0; k < a[i].size(); k++) {
for(int p = k + 1; p < a[i].size(); p++) {
ans += a[j].size() * 1LL * abs((a[i][p] - a[i][k]) * 1LL * (i - j));
}
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp setprecision(4)<<fixed
#define ss second
#define fori(v) for(int i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define lli long long int
#define MAX 1100
#define double long double
#define ch 400
int inf = pow(10,9);
lli modulo = pow(10,9)+7;
lli md = pow(10,9)+7;
double eps = 1e-13;
ifstream in;
ofstream out;
//#define cin in
//#define cout out
void deal(){
int t;
cin>>t;
forl(t){
int n;
cin>>n;
int arr[n];
lli sum = 0;
fori(n){
cin>>arr[i];
sum+=arr[i];
for(int j=i-1; j>-1; j--){
int mn = min(arr[i],arr[j]);
if(mn<=(arr[i]&arr[j]))
sum+=mn;
}
}
cout<<sum<<'\n';
}

pre[0] = 0;
for(int i = 0; i < a[1].size(); i++) {
pre[i + 1] = pre[i] + a[1][i];
}

for(int i = 0; i < a[0].size(); i++) {
int start = 0;
for(int j = 0; j < a[2].size(); j++) {
ll tot = a[0][i] + a[2][j];
while(start < cnt[1] && 2*a[1][start] < tot) start++;
ll contri = ((tot * start) - (2LL * pre[start])) + ((2LL * (pre[cnt[1]] - pre[start])) - (tot * (cnt[1] - start)));
ans += contri;
}
}
double res = double(ans) / 2.0;
cout<<setprecision(7)<<fixed<<res<<'\n';
}

int main() {
int t;
scanf("%d", &t);
while(t--) {
solve();
}
}
deal();
}

0 comments on commit 0f8a520

Please sign in to comment.