Skip to content

Instantly share code, notes, and snippets.

/*
https://www.hackerrank.com/contests/w5/challenges/kundu-and-tree
*/
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 100010
#include <vector>
#include <string>
#include <iostream>
#include <cassert>
using namespace std;
/*
BigInt multiply. Use uchar array to store the binary representation.
1. It should be unsigned char (not char);
2. Use carry, and do multiply/add iteratively, this could avoid overflow;
@sturgle
sturgle / NioTcpClient.java
Created September 29, 2014 08:29
A java nio tcp client. Keep it here as notes.
// TCP Client (Java NIO)
// A minimalistic Java NIO TCP client. Stays always connected. Disconnects and reconnects on any exception in the event handlers (onConnect, onDisconnect, onRead).
package net.bobah.nio;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
@sturgle
sturgle / exmap.cpp
Created October 13, 2014 04:05
enhanced map with random
#include <vector>
#include <map>
#include <utility>
#include <iostream>
using namespace std;
class ExMap {
map<int, int> _map; // key to index of _keyVals
vector<pair<int,int>> _keyVals;
/*
f[i][n] = f[i-1][n-1]*C(n,1) + f[i-1][n02]*C(n,2) + ... + f[i-1][i-1] * C(n, n-(i-1));
*/
#include <iostream>
#include <vector>
using namespace std;
int base = 1000000007;
typedef long long llong;
#include <iostream>
#include <vector>
#include <string>
using namespace std;
/*
Small data test pass
*/
typedef long long llong;
//248_next_min_number.cpp
// by cydu
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
/*
by cpcs
*/
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
@sturgle
sturgle / buildBstFromPreOrder.cpp
Created October 27, 2014 04:06
build bst from pre order array
#include <vector>
#include <stack>
#include <iostream>
using namespace std;
struct ListNode {
int val;
ListNode *left;
ListNode *right;
ListNode(int _val) : val(_val), left(NULL), right(NULL) {}
#include <vector>
#include <algorithm>
using namespace std;
struct Road {
int start;
int end;
int val;
};