Skip to content

Instantly share code, notes, and snippets.

#include <assert.h>
#include <stdio.h>
#include <string.h>
typedef int T;
/**
* [Sorting network](http://en.wikipedia.org/wiki/Sorting_network)
*/
void sort8(T ar[], int n) {
#!/usr/bin/python2
import sys
import re
records = []
for line in sys.stdin:
records.append(re.match(r'[ ]*(\d)+ ([^ ]+)(.*)', line.rstrip()).groups())
for record in sorted(records, key=lambda d:int(d[0])*(len(d[1])+len(d[2])), reverse=True):
print "%s %s%s" % record
@henix
henix / putint.c
Created September 11, 2013 07:40
putint
inline void putint(int n)
{
static char buf[20];
register int pos;
register int x = n;
if (x == 0) {
putchar('0');
return;
}
if (x == INT_MIN) { // x = -x do not work for the minimal value of int, so process it first
@henix
henix / getint.c
Created September 11, 2013 07:43
getint
int getint(char end) {
int s = 0;
int ch;
ch = getchar();
while (ch != end && ch != EOF) {
s = s * 10 + ch - '0';
ch = getchar();
}
return s;
}
@henix
henix / putllong.c
Created September 11, 2013 18:13
putllong
static inline void putllong(long long n)
{
static char buf[20];
register int pos;
register long long x = n;
if (x == 0) {
putchar('0');
return;
}
if (x == LLONG_MIN) { // x = -x do not work for the minimal value of long long, so process it first
@henix
henix / mergesort.c
Last active December 22, 2015 21:39
mergesort to count inversions template for ACM/ICPC
typedef int T;
inline bool less(T a, T b) {
return a < b;
}
inline bool lessEq(T a, T b) {
return a <= b;
}
@henix
henix / getint2.c
Created September 16, 2013 06:54
with sign
int getint2(int *out) {
register int s = 0;
register int ch;
ch = getchar();
bool negative = false;
while (ch < '0' || ch > '9') {
if (ch == '-') {
negative = true;
ch = getchar();
break;
/*************
* colors.js *
*************
*
* You're almost at the exit. You just need to get past this
* color lock.
*
* Changing your environment is no longer enough. You must
* learn to change yourself. I've sent you a little something
* that should help with that.
@henix
henix / rel.sh
Created December 26, 2014 06:01
rel() {
[ ! -d 'target/universal/stage' ] && echo stage not exist! && return 1
name=$(pwd | tr '/' '\n' | tail -n1)
timestamp=$(date +%Y%m%d_%H%M%S)
cp -r "target/universal/stage" "/apps/$name/stage-$timestamp"
ln -sTv "stage-$timestamp" "/apps/$name/stage"
}
@henix
henix / fcicq-question.txt
Created February 27, 2018 10:55 — forked from fcicq/fcicq-question.txt
A simple question
有一存有整数的数组 A[n] (n <= 2^31 - 1, 但需要的话可以再扩大), 其中 0 <= i, A[i] <= n-1 且 i!=j 时 A[i]!=A[j] (即一个排列). 用你认为*最高效*的方法求 B=A^(-1) (即对范围内满足 A[B[i]]=i 的 B)