Skip to content

Instantly share code, notes, and snippets.

View atupal's full-sized avatar

kangle yu atupal

View GitHub Profile
//source here
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
using namespace std;
const int N = 210;
/*
网络流 之 最大流 增广路算法 http://blog.163.com/art_budder_niu/blog/static/1393646202010322115138703/
FF算法:分为三个步骤,首先寻找一条增广路(如果没有增广路,则返回最大流),同时保存路径;其次,对路径上的流量求最小值,记为min;最后根据路径修改网络,对于前向边,减去最小值,对于后向边,加上最小值,或者直接修改容量。
增广路:从源点s到汇点t的一条有向路径,如果从源点开始不可以到汇点,那么没有增广路。
保存:用一个数组保存,一般是采用父亲表示法(父链接),保存当前节点的父亲, 寻找的时候采用的是迭代的方式实现求最小值以及修改原网络。
寻找增广路,采用bfs的方式。详细算法如下:
*/
@atupal
atupal / 神写的kmp.cpp
Created April 15, 2013 05:35
字符串树上的kmp,dfs
#pragma comment (linker, "/STACK:100000000")
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define N 101000
char s[3*N];
int p[3*N], l, r;
vector <int> m[N];
string w[N];
@atupal
atupal / xrun.sh
Created May 16, 2013 04:25
打开一个新的X
#!/bin/bash
#xinit appname -- :10
# calculate first available VT
LVT=`fgconsole --next-available`
# calculate first usable display
XNUM="-1"
SOCK="something"
while [ ! -z "$SOCK" ]
@atupal
atupal / msvcrt_input.py
Created June 26, 2013 06:31
python set time limit on input
import msvcrt
import time
def raw_input_with_timeout(prompt, timeout=30.0):
finishat = time.time() + timeout
result = []
while True:
if msvcrt.kbhit():
result.append(msvcrt.getche())
if result[-1] == '\r': # or \n, whatever Win returns;-)
@atupal
atupal / select_input.py
Created June 26, 2013 06:36
Keyboard input with timeout in Python
import sys, select
print "You have ten seconds to answer!"
i, o, e = select.select( [sys.stdin], [], [], 10 )
if (i):
print "You said", sys.stdin.readline().strip()
else:
print "You said nothing!"
#!/usr/bin/env python
"""
Define a Timer context manager, allowing to measure the
wall time of the code block it contains.
Example:
>>> with Timer() as timer:
... for i in xrange(10000000):
... pass
...
@atupal
atupal / use_mount_bind
Created July 4, 2013 13:36
How to get git to follow symlinks
what i did to add to get the files within a symlink into git (i didn't use a symlink but):
sudo mount --bind SOURCEDIRECTORY TARGETDIRECTORY
do this command in the git managed directory. TARGETDIRECTORY has to be created before the SOURCEDIRECTORY is mounted into it.
works fine! that trick helped me with subversion too. i use it to include files from an Dropbox account, where a webdesigner does his stuff.
@atupal
atupal / python_long_socket.py
Created July 5, 2013 18:03
python 长链接
#coding=utf-8
'''''
socket 给百度发送http请求
连接成功后,发送http的get请求,所搜索功能
'''
import socket
import sys
import time