Skip to content

Instantly share code, notes, and snippets.

@agasiev
agasiev / CodeforcesProblems.py
Created January 28, 2013 03:25
Codeforces.ru list of tags
#!/usr/bin/env python
# -*- coding: utf-8
# Codeforces.ru problem tag analysis.
import simplejson
import urllib2
import re
result = dict()
@agasiev
agasiev / SimpleCalculator.cpp
Last active December 11, 2015 08:39
Calculator
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <stack>
#include <sstream>
@agasiev
agasiev / Dijkstra.cpp
Created December 26, 2012 22:37
Dijkstra path search algorithm
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int main(int, char**) {
int n = 0;
cin >> n;
vector<vector<pair<int, int> > > g(n);
@agasiev
agasiev / BinarySearch.cpp
Created December 26, 2012 13:42
Binary search
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int bsearch(vector<int> a, int left, int right, int what) {
if (right < left) return -1;
int middle = left + (right - left)/2;
@agasiev
agasiev / MergeSort.cpp
Created December 26, 2012 13:11
Merge sort with iterators
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void msort(vector<int>::iterator left, vector<int>::iterator right) {
if (right - left <= 1) return;
msort(left, left + (right - left)/2);
#!/usr/bin/env python
# -*- coding: utf-8
from SqlHelper import SqlHelper
import string
import re
import sys
from SqlHelper import SqlHelper
sql = SqlHelper()
#!/usr/bin/env python
# -*- coding: utf-8
import string
import re
import sys
from SqlHelper import SqlHelper
sql = SqlHelper()
@agasiev
agasiev / topological_sort.cpp
Created December 6, 2012 23:52
Topological sort
using namespace std;
vector<vector<int> > g;
vector<bool> used;
vector<int> result;
void dfs(int n) {
used[n] = true;
for (int i = 0; i < g[n].size(); i++) {
if (!used[g[n][i]]) {
@agasiev
agasiev / KMP_prefix.cpp
Created December 6, 2012 23:24
KMP prefix function
std::vector<unsigned> kmp_prefix_function(std::string s) {
size_t n = s.size();
std::vector<unsigned> result(n);
for (int i = 1; i < n; i++) {
int j = result[i-1];
while (j > 0 && s[i] != s[j])
j = result[j-1];
@agasiev
agasiev / trivial_prefix.cpp
Created December 3, 2012 23:51
Trivial implementation of prefix function
std::vector<unsigned> trivial_prefix_function(std::vector<unsigned> & prefix, std::string s) {
prefix.resize(s.length());
for (int i = 0; i < s.length(); ++i)
for (int j = 0; j <= i; ++j)
if (s.substr(0, j) == s.substr(i - j + 1, j))
prefix[i] = j;
return prefix;
}