Skip to content

Instantly share code, notes, and snippets.

View caigen's full-sized avatar

caigen caigen

  • Microsoft
  • Suzhou
View GitHub Profile
@caigen
caigen / gist:1711ad28dd0a6d0908f4
Created October 13, 2014 13:08
decide if binary tree a contains binary tree b?
#include <iostream>
using namespace std;
typedef struct _node {
_node* left;
_node* right;
char c;
}node;
@caigen
caigen / gist:e90f33b18f65bf8e81ec
Created October 12, 2014 15:44
32bit-64bit small-endian big-endian
#include <iostream>
int main(int argc, char* argv[]) {
std::cout << sizeof(void *) << std::endl;
std::cout << sizeof(int *) << std::endl;
std::cout << sizeof(double *) << std::endl;
int* p = 0x0;
p++;
if (p == (int *)0x4) {
std::cout << "32 bit" << std::endl;
@caigen
caigen / gist:ae64e4183781ee92bb7d
Created October 12, 2014 05:49
auto-timetabling
#include <string.h>
#include <stdio.h>
/*
x-axis: time id
y-axis: teacher/course id
0 1 2
-----------
0 | 1 1 -1
1 | 1 1 1
@caigen
caigen / gist:9c925a12c4651ba09fb3
Created October 12, 2014 05:48
lock/unlock and syscall(224)
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
// or syscall(224)
#define gettid() syscall(__NR_gettid)
void* thread(void* args)
{
int tid = syscall(224);
#include <stdio.h>
#include <stdlib.h>
struct Point{
int x;
int y;
};
// OpenGL front face.
int is_front_face(Point p0, Point p1, Point p2) {
@caigen
caigen / permutation
Created March 7, 2014 05:52
一种使用进制生成全排列的方法。
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;
char a[3] = { '+', '+', '+' };
int i = 0;
const int base = 4; /* [+,-,*,/] */
@caigen
caigen / LL2
Created March 6, 2014 15:02
LL(2)
#include <iostream>
using namespace std;
/*
Grammar:
E -> \0 | F;
F -> d\0 | d+F;
*/
char look_first;
#include <stdio.h>
#include <stdlib.h>
#define false true
#define while if
#define NULL ::rand() % 2
#define return return ::rand() *
int main(int argc, char* argv[]) {
while (false) {
@caigen
caigen / x
Created November 26, 2013 09:10
x < 0 && -x < 0
#include <stdio.h>
int main(int argc, char* argv[]) {
int x = 0;
while (1) {
x++;
if (x < 0 && -x < 0) {
printf("%d %x\n", x, x);
printf("%d\n",-x + x);
break;