Skip to content

Instantly share code, notes, and snippets.

@coyotebush coyotebush/falling.c
Created Apr 13, 2014

Embed
What would you like to do?
My submissions to KTH Challenge 2014
#include <stdio.h>
int main() {
int D, n1, n2;
scanf("%d", &D);
for (n1 = 0; n1 < D; n1++)
for (n2 = 0; n2 < n1; n2++)
if ((n1 + n2) * (n1 - n2) == D) {
printf("%d %d\n", n2, n1);
return 0;
}
printf("impossible\n");
return 0;
}
#!/usr/bin/python3
import heapq
N, M = [int(x) for x in input().split()]
links = dict()
for i in range(M):
u, v, w = [int(x) for x in input().split()]
if u not in links:
links[u] = set()
links[u].add((v, w))
s, t = [int(x) for x in input().split()]
best = dict()
paths = list()
q = list()
heapq.heappush(q, (0, s, set([s])))
while len(q) > 0:
d, u, path = heapq.heappop(q)
if u == t:
paths.append(path)
elif u in links:
for v, w in links[u]:
if v not in best or d + w <= best[v]:
best[v] = d + w
heapq.heappush(q, (d + w, v, path.union([v])))
common = paths[0].intersection(*paths[1:])
common = [str(x) for x in common]
print(" ".join(common))
#!/usr/bin/python3
i = input()
try:
h, d = i.split()
except ValueError:
h = i
d = ""
n = 1
for p in d:
n = n * 2
if p == 'R':
n = n + 1
n = 2 ** (int(h) + 1) - n
print(n)
#include <stdio.h>
int main() {
double D, lo = 0.0, hi = 1.0, templo, temphi;
int N, c, i, sum = 0;
scanf("%lf %d", &D, &N);
for (i = 1; i <= N; i++) {
scanf("%d", &c);
sum = sum + c;
templo = sum - i*D;
temphi = templo + 1;
if (lo < templo)
lo = templo;
if (hi > temphi)
hi = temphi;
if (lo > hi) {
printf("impossible\n");
return 0;
}
}
printf("possible\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.