Skip to content

Instantly share code, notes, and snippets.

@jakab922
jakab922 / bit_part.py
Created May 5, 2018 07:25
Google Code Jam 2018 / 1A / Bit Party
t = int(raw_input().strip())
M, S, P = range(3)
def show(case, sol):
print "Case #%s: %s" % (case, sol)
def transform(m, s, p, limit):
@jakab922
jakab922 / sol.py
Created April 30, 2018 10:20
Mysterious road signs
from collections import defaultdict as dd
def show(i, key, count):
print "Case #%s: %s %s" % (i, key, count)
t = int(raw_input().strip())
for ct in xrange(1, t + 1):
s = int(raw_input().strip())
@jakab922
jakab922 / dynamic_line_intersection.py
Last active April 30, 2018 06:49
Dynamic line intersection
from math import sqrt, ceil
LIMIT = 10 ** 5
n = int(raw_input().strip())
SLIMIT = int(ceil(sqrt(LIMIT)))
small = [[0] * (SLIMIT + 1) for _ in xrange(SLIMIT + 1)]
big = [0 for _ in xrange(LIMIT + 1)]
@jakab922
jakab922 / sol.py
Created April 29, 2018 20:09
Code Jam 18 / 1B / Rounding Error
from heapq import heappop as pop, heappush as push
from math import floor, ceil
t = int(raw_input().strip())
def show(i, sol):
print "Case #%s: %s" % (i, sol)
@jakab922
jakab922 / centroid.py
Created April 28, 2018 21:22
Centroid tree of a tree in O(n * log_{2}(n)) time.
from collections import defaultdict as dd
def _calc_size(tree, root, found, sizes):
"""Practically a dfs on the remaining nodes
where the size of the parent node is the sum of
sizes of the child nodes."""
stack = [(root, 0)]
on_route = set([root])
@jakab922
jakab922 / sol.cc
Created April 22, 2018 23:00
Solution for Topcoder Open 2018 / 1A / 1000
#include <vector>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <iostream>
using namespace std;
typedef long long ll;
n = int(raw_input().strip())
acc = []
for _ in xrange(n):
c = int(raw_input().strip())
if c >= 90:
acc.append(c)
if acc:
print "%.2f" % (sum(acc) / float(len(acc)))
@jakab922
jakab922 / stuff.py
Last active January 19, 2018 09:58
Testing example
# kmp.py
def get_prefix(string):
l = len(string)
ret = [0] * l
border = 0
for i in xrange(1, l):
while border > 0 and string[i] != string[border]:
border = ret[border - 1]
if string[i] == string[border]:
border += 1
@jakab922
jakab922 / sanitize.py
Created December 18, 2017 14:52
Script for sanitizing python projects so that code intelligence works in them
import os.path
import os
def touch(fname, times=None):
"""via: https://stackoverflow.com/a/1160227/8785384 """
with open(fname, "a"):
os.utime(fname, times)
@jakab922
jakab922 / cards.py
Created November 30, 2017 06:33
Finding the missing Dobble cards
symbols = [
"sziv", "virag", "ora", "villanykorte", "teknos", "pok", "cica", "szmotyi",
"kerdojel", "sajt", "katica", "lakat", "nap", "hopehely", "tilos",
"napszemuveg", "felkialtojel", "emberke", "jinjang", "tuz", "pokhalo", "madar",
"bohoc", "kalapacs", "iglu", "dino", "gyertya", "szaj", "fa", "hoember", "ollo", "lohere",
"hangjegy", "sakk", "szellem", "vizcsepp", "hold", "vasmacska", "jeg", "cumi", "bomba",
"zebra", "kutya", "koponya", "repa", "alma", "ceruza", "villam", "kaktusz", "auto",
"kez", "celkereszt", "szem", "delfin", "level", "sarkany", "kulcs" ]
s = set(symbols)
print "The number of symbols are: %s" % (len(symbols), )