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 e5e7ca6

Browse files
Last batch of DMOJ files
1 parent bceb126 commit e5e7ca6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+4252
-0
lines changed

‎DMOJ/aplusb.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
raw_input = sys.stdin.readline
3+
tc = int(raw_input())
4+
while tc:
5+
tc -= 1
6+
a,b = [int(i) for i in raw_input().split()]
7+
print a + b

‎DMOJ/bf1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python2.7
2+
# -*- coding : utf-8 -*-
3+
a = int(raw_input())
4+
v = []
5+
for i in xrange(a):
6+
j = int(raw_input())
7+
v.append(j)
8+
v.sort()
9+
for i in v:
10+
print i

‎DMOJ/bf1hard.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python2.7
2+
# -*- coding : utf-8 -*-
3+
from sys import stdin
4+
raw_input = stdin.readline
5+
a = int(raw_input())
6+
v = []
7+
for i in xrange(a):
8+
j = int(raw_input())
9+
v.append(j)
10+
v.sort()
11+
for i in v:
12+
print i

‎DMOJ/boolean.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python2.7
2+
# -*- coding : utf-8 -*-
3+
a = raw_input()
4+
print eval(a)

‎DMOJ/ccc10j5.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python2.7
2+
# -*- coding : utf-8 -*-
3+
from collections import deque
4+
def bfs(graph,start,end):
5+
visited = set()
6+
queue = deque([(0,start)])
7+
while queue:
8+
distance,v = queue.popleft()
9+
if v == end:
10+
return distance
11+
if v not in visited:
12+
visited.add(v)
13+
for i in graph.get(v,[]):
14+
queue.append((distance+1,i))
15+
return -1
16+
dicio = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8}
17+
grafo = {}
18+
for i in xrange(1,9):
19+
for j in xrange(1,9):
20+
complexo = complex(i,j)
21+
grafo[complexo] = [complexo+complex(1,2),complexo+complex(-1,2),complexo+complex(1,-2),complexo+complex(-1,-2),complexo+complex(2,1),complexo+complex(2,-1),complexo+complex(-2,1),complexo+complex(-2,-1)]
22+
a,b = [int(i) for i in raw_input().split()]
23+
c,d = [int(i) for i in raw_input().split()]
24+
print bfs(grafo,complex(a,b),complex(c,d))

‎DMOJ/ccc96s4.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python2.7
2+
# -*- coding : utf-8 -*-
3+
def to_roman(entrada):
4+
array = []
5+
for a,b in [("M",1000),("CM",900),("D",500),("CD",400),("C",100),("XC",90),("L",50),("XL",40),("X",10),("IX",9),("V",5),("IV",4),("I",1)]:
6+
total = int(entrada/b)
7+
for k in xrange(total):
8+
array.append(a)
9+
entrada %= b
10+
return "".join(array)
11+
mapa = {}
12+
for i in xrange(1,1001):
13+
mapa[to_roman(i)] = i
14+
casos = int(raw_input())
15+
for vez in xrange(casos):
16+
a,b = raw_input().replace("+"," ").replace("=","").split()
17+
xa = 1001
18+
if a in mapa:
19+
xa = mapa[a]
20+
xb = 1001
21+
if b in mapa:
22+
xb = mapa[b]
23+
resultado = xa+xb
24+
if resultado <= 1000:
25+
print "%s+%s=%s" % (a,b,to_roman(resultado))
26+
else:
27+
print "%s+%s=CONCORDIA CUM VERITATE" % (a,b)

‎DMOJ/cco10p6.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python2.7
2+
# -*- coding : utf-8 -*-
3+
alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"
4+
tamanho = 27
5+
binario = [{}]
6+
for i in alfabeto:
7+
binario[0][i] = i
8+
logartimos = range(32)
9+
for i in alfabeto:
10+
davez = raw_input()
11+
binario.append({})
12+
binario[1][i] = davez
13+
vez = int(raw_input())
14+
raiz = min(int(vez**0.5)+1,vez)
15+
for i in xrange(2,raiz+1):
16+
binario.append({})
17+
for j in alfabeto:
18+
binario[i][j] = binario[1][binario[i-1][j]]
19+
resto = vez % raiz
20+
quociente = vez - resto
21+
quociente /= raiz
22+
if resto != 0:
23+
resposta = binario[resto]
24+
elif resto == 0 and vez != 0:
25+
resposta = binario[raiz]
26+
for i in xrange(quociente):
27+
for j in alfabeto:
28+
resposta[j] = binario[raiz][resposta[j]]
29+
entrada = [resposta[i] for i in raw_input()]
30+
print "".join(entrada)

‎DMOJ/coci15c3p1.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
n = int(raw_input())
2+
resposta = 0
3+
for i in xrange(n):
4+
a = [i for i in raw_input()]
5+
b = int(a[-1])
6+
a.pop(-1)
7+
c = int("".join(a))
8+
resposta += c**b
9+
print resposta

‎DMOJ/coci15c4p3.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <cstdio>
2+
int vetor[1010];
3+
int main(){
4+
int n;
5+
scanf("%d",&n);
6+
for(int i=1;i<=n;i++){
7+
for(int j=1;j<=n;j++){
8+
int k;
9+
scanf("%d",&k);
10+
vetor[i] |= k;
11+
vetor[j] |= k;
12+
}
13+
}
14+
for(int i=1;i<=n;i++) printf("%d ",vetor[i]);
15+
printf("\n");
16+
return 0;
17+
}

‎DMOJ/coci15c4p4.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
ll N,K,Q;
5+
ll get_pow(ll pot){
6+
ll resp = 1;
7+
for(ll i=1;i<=pot;i++) resp *= K;
8+
return resp;
9+
}
10+
ll get_level(ll x){
11+
ll pot = 1,nivel = 0;
12+
while(x > 0){
13+
//printf("%lld\n",x);
14+
x -= pot;
15+
pot *= K;
16+
nivel++;
17+
}
18+
return nivel;
19+
}
20+
ll get_first_level(ll nivel){
21+
if(nivel == 0) return 1;
22+
ll ac = 0;
23+
ll pot = 1;
24+
for(ll i = 1;i <nivel;i++){
25+
ac += pot;
26+
pot *= K;
27+
}
28+
return ac + 1;
29+
}
30+
ll get_parent(ll x){
31+
if(x == 1) return 1;
32+
ll nivel = get_level(x);
33+
ll primeiro = get_first_level(nivel - 1);
34+
ll ultimo = get_first_level(nivel) - 1;
35+
ll ini = primeiro, fim = ultimo,meio;
36+
while(ini <= fim){
37+
meio = (ini + fim)/2;
38+
ll delta = meio - primeiro;
39+
ll esimo1 = ultimo + 1 + delta*K;
40+
ll esimok = esimo1 + K - 1;
41+
if(esimo1 <= x && x <= esimok){
42+
return meio;
43+
}
44+
if(x < esimo1){
45+
fim = meio - 1;
46+
}
47+
else ini = meio + 1;
48+
}
49+
}
50+
ll LCA(ll u, ll v){
51+
while(u != v){
52+
if(get_level(u ) < get_level(v)) swap(u,v);
53+
//printf("U %lld P %lld\n",u,get_parent(u));
54+
u = get_parent(u);
55+
}
56+
return u;
57+
}
58+
int main(){
59+
scanf("%lld %lld %lld",&N,&K,&Q);
60+
while(Q--){
61+
ll u,v;
62+
scanf("%lld %lld",&u,&v);
63+
printf("%lld\n",get_level(u) + get_level(v) - 2*get_level(LCA(u,v)));
64+
}
65+
return 0;
66+
}

0 commit comments

Comments
(0)

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