Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4b393a4

Browse files
COCI problems
1 parent 9e0a969 commit 4b393a4

19 files changed

+652
-0
lines changed

‎DMOJ/coci06c1p4.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Ivan Carvalho
2+
// Solution to https://dmoj.ca/problem/coci06c1p4
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef tuple<int,int,int> trinca;
7+
8+
const int INF = 3000;
9+
const int MAXR = 53;
10+
const int dx[4] = {1,-1,0,0};
11+
const int dy[4] = {0,0,1,-1};
12+
13+
char entrada[MAXR][MAXR];
14+
int dist_flood[MAXR][MAXR],ok[MAXR][MAXR],dist_source[MAXR][MAXR],x_i,y_i;
15+
int R,C;
16+
17+
inline int valido(int a,int b){
18+
return min(a,b) >= 0 && a < R && b < C && entrada[a][b] != 'X';
19+
}
20+
21+
int main(){
22+
23+
scanf("%d %d",&R,&C);
24+
25+
queue<trinca> bfs;
26+
27+
for(int i = 0;i<R;i++){
28+
scanf("%s",entrada[i]);
29+
for(int j = 0;j<C;j++){
30+
dist_flood[i][j] = INF;
31+
if(entrada[i][j] == 'S'){
32+
x_i = i;
33+
y_i = j;
34+
}
35+
if(entrada[i][j] == '*'){
36+
bfs.push(make_tuple(0,i,j));
37+
}
38+
}
39+
}
40+
41+
while(!bfs.empty()){
42+
trinca davez = bfs.front();
43+
bfs.pop();
44+
int x = get<1>(davez),y = get<2>(davez),z = get<0>(davez);
45+
if(ok[x][y]) continue;
46+
ok[x][y] = 1;
47+
if(entrada[x][y] == 'D') continue;
48+
dist_flood[x][y] = z;
49+
for(int i = 0;i<4;i++){
50+
int nx = x + dx[i],ny = y + dy[i];
51+
if(!valido(nx,ny)) continue;
52+
bfs.push(make_tuple(z+1,nx,ny));
53+
}
54+
}
55+
56+
memset(ok,0,sizeof(ok));
57+
58+
bfs.push(make_tuple(0,x_i,y_i));
59+
60+
while(!bfs.empty()){
61+
trinca davez = bfs.front();
62+
bfs.pop();
63+
int x = get<1>(davez),y = get<2>(davez),z = get<0>(davez);
64+
if(ok[x][y]) continue;
65+
ok[x][y] = 1;
66+
//printf("X %d Y %d Z %d D %d\n",x,y,z,dist_flood[x][y]);
67+
if(entrada[x][y] == 'D'){
68+
printf("%d\n",z);
69+
return 0;
70+
}
71+
if(z >= dist_flood[x][y]){
72+
continue;
73+
}
74+
for(int i = 0;i<4;i++){
75+
int nx = x + dx[i],ny = y + dy[i];
76+
if(!valido(nx,ny)) continue;
77+
bfs.push(make_tuple(z+1,nx,ny));
78+
}
79+
}
80+
81+
printf("KAKTUS\n");
82+
83+
return 0;
84+
85+
}

‎DMOJ/coci06c2p4.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Ivan Carvalho
2+
# Solution to https://dmoj.ca/problem/coci06c2p4
3+
4+
N = int(input())
5+
ans = 0
6+
7+
for i in range(1,N+1):
8+
for j in range(i+2,N+1):
9+
a = j - i - 1
10+
b = N - a - 2
11+
ans += a*b
12+
13+
print(ans//2)

‎DMOJ/coci07c1p3.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Ivan Carvalho
2+
# Solution to https://dmoj.ca/problem/coci07c1p3
3+
4+
def min_dist(X,Y):
5+
ans = abs(Y[0] - X)
6+
for Z in Y:
7+
ans = min(ans, abs(Z - X) )
8+
return ans
9+
10+
N = int(input())
11+
12+
P = sorted([int(i) for i in input().split()])
13+
A,B = [int(i) for i in input().split()]
14+
15+
C = []
16+
17+
for i in range(N-1):
18+
L = (P[i]+P[i+1])//2
19+
C.append(L)
20+
C.append(L+1)
21+
C.append(L-1)
22+
23+
C.append(A)
24+
C.append(A+1)
25+
C.append(B)
26+
C.append(B-1)
27+
28+
D = []
29+
for i in C:
30+
if i < A or i > B:
31+
continue
32+
if i % 2 == 0:
33+
continue
34+
D.append((min_dist(i,P),i))
35+
36+
D.sort()
37+
print(D[-1][1])

‎DMOJ/coci07c2p3.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Ivan Carvalho
2+
# Solution to https://dmoj.ca/problem/coci07c2p3
3+
4+
R,C = [int(i) for i in input().split()]
5+
6+
matriz = [["#"]*(C+2)]
7+
for i in range(R):
8+
entrada = input()
9+
linha = ["#"] + [j for j in entrada] + ["#"]
10+
matriz.append(linha)
11+
matriz.extend([["#"]*(C+2)])
12+
13+
candidatos = []
14+
15+
for i in range(R+2):
16+
palavra = "".join(matriz[i])
17+
validos = [p for p in palavra.split("#") if len(p) >= 2]
18+
candidatos.extend(validos)
19+
20+
for i in range(C+2):
21+
palavra = ""
22+
for j in range(R+2):
23+
palavra += matriz[j][i]
24+
validos = [p for p in palavra.split("#") if len(p) >= 2]
25+
candidatos.extend(validos)
26+
27+
print(sorted(candidatos)[0])

‎DMOJ/coci07c4p1.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Ivan Carvalho
2+
# Solution to https://dmoj.ca/problem/coci07c4p1
3+
4+
def simulate(x,y,z):
5+
while True:
6+
x -= y
7+
if x <= 0:
8+
return 1
9+
x -= z
10+
if x <= 0:
11+
return 0
12+
13+
a,b,c,d = [int(i) for i in input().split()]
14+
times = [int(i) for i in input().split()]
15+
16+
for t in times:
17+
print(["none","one","both"][simulate(t,a,b) + simulate(t,c,d)])

‎DMOJ/coci08c2p3.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Ivan Carvalho
2+
// Solution to https://dmoj.ca/problem/coci08c2p3
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
int main(){
7+
8+
int N;
9+
cin >> N;
10+
11+
vector<int> A(N),B(N);
12+
for(int i = 0;i<N;i++){
13+
cin >> A[i] >> B[i];
14+
}
15+
16+
int best = abs(A[0] - B[0]);
17+
18+
for(int bitmask = 1;bitmask<(1 << N);bitmask++){
19+
int produto = 1, soma = 0;
20+
for(int i = 0;i<N;i++){
21+
if(!(bitmask & (1 << i))) continue;
22+
produto *= A[i];
23+
soma += B[i];
24+
}
25+
best = min(best, abs(soma - produto) );
26+
}
27+
28+
printf("%d\n",best);
29+
30+
return 0;
31+
32+
}

‎DMOJ/coci08c5p2.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Ivan Carvalho
2+
# Solution to https://dmoj.ca/problem/coci08c5p2
3+
from math import gcd
4+
5+
a,b = [int(i) for i in input().split()]
6+
7+
c = gcd(a,b)
8+
9+
i = 1
10+
while i*i <= c:
11+
if c % i != 0:
12+
i += 1
13+
continue
14+
print("%d %d %d" % (i,a/i,b/i))
15+
if i*i != c:
16+
j = c/i
17+
print("%d %d %d" % (j,a/j,b/j))
18+
i += 1

‎DMOJ/coci09c1p1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Ivan Carvalho
2+
# Solution to https://dmoj.ca/problem/coci09c1p1
3+
4+
tones = [int(i) for i in input().split()]
5+
6+
if tones == list(range(1,9)):
7+
print("ascending")
8+
elif tones == list(range(1,9))[::-1]:
9+
print("descending")
10+
else:
11+
print("mixed")

‎DMOJ/coci09c1p2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Ivan Carvalho
2+
# Solution to https://dmoj.ca/problem/coci09c1p2
3+
4+
n = int(input())
5+
ans = 0
6+
7+
for i in range(n+1):
8+
for j in range(i,n+1):
9+
ans += i + j
10+
11+
print(ans)

‎DMOJ/coci14c3p1.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Ivan Carvalho
2+
# Solution to https://dmoj.ca/problem/coci14c3p1
3+
4+
tipo = ["1QAZ","2WSX","3EDC","4RFV5TGB","6YHN7UJM","8IK,","9OL.","0P;//-=[]'"]
5+
qtd = [0 for i in range(len(tipo))]
6+
a = input()
7+
8+
for i in a:
9+
for j in range(len(tipo)):
10+
if i in tipo[j]:
11+
qtd[j]+=1
12+
break
13+
else:
14+
print("Invalid Input")
15+
16+
for i in qtd:
17+
print(i)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /