Skip to content

Instantly share code, notes, and snippets.

@msg555
msg555 / pizza_baking.cpp
Last active January 1, 2016 02:19
Solution to Pizza Baking from Round 3 of the 2014 Hacker Cup
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <map>
#include <numeric>
#include <queue>
@msg555
msg555 / J.cpp
Created April 14, 2014 00:32
Solution to Sharing Chocolage from WF10 Problem J
#include <iostream>
#include <cstring>
#include <cstdio>
#include <numeric>
using namespace std;
typedef unsigned int u4;
#define MAXN 15
@msg555
msg555 / geo.cpp
Last active August 29, 2015 14:00
#include <algorithm>
#include <vector>
#include <complex>
#include <cmath>
using namespace std;
static bool geoerror;
// #define USE_FLOAT
@msg555
msg555 / queen.cpp
Created April 30, 2014 01:40
Solution to SPOJ's QUEEN
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdio>
@msg555
msg555 / queen2.cpp
Last active August 29, 2015 14:00
Updated solution to SPOJ's QUEEN
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cstdlib>
@msg555
msg555 / queen2.s.cpp
Last active August 29, 2015 14:00
More QUEEN nonsense
asm(
" .file \"queen2.cpp\"\n"
" .section .text._ZN2IO10skip_spaceEv,\"axG\",@progbits,_ZN2IO10skip_spaceEv,comdat\n"
" .align 2\n"
" .p2align 4,,15\n"
" .weak _ZN2IO10skip_spaceEv\n"
" .type _ZN2IO10skip_spaceEv, @function\n"
"_ZN2IO10skip_spaceEv:\n"
".LFB685:\n"
" .cfi_startproc\n"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/* Recovers k increasing disjoint subsequences that cover the maximum possible
* number of elements from A. Runs in O(MN) time where M is the resulting
* number of elements on all subsequences. Based on the method
* described in section 4 of Greene's "An Extension of Schensted's Theorem".
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
int main(int argc, char** argv) {
for (int i = 1; i < argc; i++) {
DIR* dir = opendir(argv[i]);
if (!dir) {
fprintf(stderr, "failed top open directory %s\n", argv[i]);
continue;
@msg555
msg555 / dfwrap.sh
Created April 16, 2015 20:10
Dustforce Wrapper for Linux
#!/bin/sh
DIR="/home/msg555/Dustforce"
BIN="$DIR/Dustforce.bin.x86_64"
BINESC=$(echo "$BIN" | sed -e 's/[]\/$*.^|[]/\\&/g')
if ps aux | grep "$BINESC" > /dev/null; then
/bin/echo -en '\xe1\x0d\x00\x00'"$@"'\x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' | head -c 256 > "$DIR/IPC.sock"
else
"$BIN" $@
fi
@msg555
msg555 / mutex.h
Last active August 29, 2015 14:23
/* Correct answer is "OK". Most solutions incorrectly identify
* (4, 5) as a deadlock despite it not being reachable.
*/
int NumberOfOperations(long long i) {
return 8;
}
int GetOperation(long long i, long long index) {
int op1[] = {1, 2, -2, 3, 2, -2, -1, -3};