This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#xinit appname -- :10 | |
# calculate first available VT | |
LVT=`fgconsole --next-available` | |
# calculate first usable display | |
XNUM="-1" | |
SOCK="something" | |
while [ ! -z "$SOCK" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
网络流 之 最大流 增广路算法 http://blog.163.com/art_budder_niu/blog/static/1393646202010322115138703/ | |
FF算法:分为三个步骤,首先寻找一条增广路(如果没有增广路,则返回最大流),同时保存路径;其次,对路径上的流量求最小值,记为min;最后根据路径修改网络,对于前向边,减去最小值,对于后向边,加上最小值,或者直接修改容量。 | |
增广路:从源点s到汇点t的一条有向路径,如果从源点开始不可以到汇点,那么没有增广路。 | |
保存:用一个数组保存,一般是采用父亲表示法(父链接),保存当前节点的父亲, 寻找的时候采用的是迭代的方式实现求最小值以及修改原网络。 | |
寻找增广路,采用bfs的方式。详细算法如下: | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//source here | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <iostream> | |
#include <queue> | |
using namespace std; | |
const int N = 210; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <math.h> | |
const int maxn = 50001; | |
int n; | |
double x[maxn]; | |
double y[maxn]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Queue | |
import threading | |
import urllib2 | |
import time | |
from BeautifulSoup import BeautifulSoup | |
hosts = ["http://yahoo.com", "http://google.com", "http://amazon.com", | |
"http://ibm.com", "http://apple.com"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Optimized Code For Quantizing Colors to xterm256 | |
* | |
* These functions are equivalent to the ones found in xterm256.py but | |
* orders of a magnitude faster and should compile quickly (fractions | |
* of a second) on most systems with very little risk of | |
* complications. | |
* | |
* Color quantization is very complex. This works by treating RGB | |
* values as 3D euclidean space and brute-force searching for the |