Skip to content

Instantly share code, notes, and snippets.

View yinyanghu's full-sized avatar
🎯
Focusing

Jian Li yinyanghu

🎯
Focusing
View GitHub Profile
@yinyanghu
yinyanghu / lca.cc
Last active August 29, 2015 14:23
Lowest Common Ancestor (LCA) - LCA -> RMQ -> ST - O(nlogn) - O(1)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 1000 + 1
#define MAXE 2*(MAXN)
@yinyanghu
yinyanghu / st.cc
Last active August 29, 2015 14:23
RMQ - Sparse Table Algorithm
#define MAXST 100000
#define LogMAXST 18
inline int clz(int x){return __builtin_clz(x);}
inline int lg2(int x){return !x ? -1 : 31 - clz(x);}
struct SparseTable {
int N;
int F[LogMAXST][MAXST];
@yinyanghu
yinyanghu / gen.cc
Last active August 29, 2015 14:22
POJ 2104 - K-th Number http://poj.org/problem?id=2104
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
const int N = 100000;
const int M = 5000;
const int MOD = 100000000;
int A[N];
@yinyanghu
yinyanghu / bipartite_matching.cc
Last active April 9, 2017 18:14
Maximum bipartite matching - augmenting path algorithm
bool extendpath(int x) {
for (int i = 1; i <= m; ++ i)
if (edge[x][i] && flag[i]) {
flag[i] = false;
if (matching[i] == -1 || extendpath(matching[i])) {
matching[i] = x;
return true;
}
}
return false;
@yinyanghu
yinyanghu / dinic.cc
Last active April 9, 2017 19:20
Maximum Flow - Dinic Algorithm
typedef int F;
#define MAXE 50000
#define MAXV 20000
#define F_INF 1000000
struct MaxFlow {
int V, E;
int start[MAXV], next[MAXE], v[MAXE];
int used[MAXV], level[MAXV];
F cap[MAXE], flow[MAXE];
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
class Solution {
public:
void solve(vector< vector<char> > &board);
};
void Solution::solve(vector< vector<char> > &board) {
int n = board.size();
@yinyanghu
yinyanghu / hou.c
Created October 31, 2014 21:26
IOCCC 2011 Winner -- Qiming Hou
#include <stdio.h>
#include <math.h>
#define clear 1;if(c>=11){c=0;sscanf(_,"%lf%c",&r,&c);while(*++_-c);}\
else if(argc>=4&&!main(4-(*_++=='('),argv))_++;g:c+=
#define puts(d,e) return 0;}{double a;int b;char c=(argc<4?d)&15;\
b=(*_%__LINE__+7)%9*(3*e>>c&1);c+=
#define I(d) (r);if(argc<4&&*#d==*_){a=r;r=usage?r*a:r+a;goto g;}c=c
#define return if(argc==2)printf("%f\n",r);return argc>=4+
#define usage main(4-__LINE__/26,argv)
#define calculator *_*(int)
#include <stdlib.h>
#include <stdio.h>
/* Create a lambda function. Note: unlike lambdas in functional
languages, this lambda does not capture the containing
environment. Thus, if you access the enclosing environment, you
must ensure that the lifetime of this lambda is bound by the
lifetime of the enclosing environment (i.e., until the enclosing
function returns). This means that if you access local
@yinyanghu
yinyanghu / LittleElephantAndDouble.cpp
Created November 23, 2013 19:54
Topcoder SRM597 Div2
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
@yinyanghu
yinyanghu / FoxAndGo.cpp
Created September 8, 2013 11:41
Topcoder SRM590 Div2
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>