Skip to content

Instantly share code, notes, and snippets.

@shnya
shnya / prob.py
Created May 25, 2011 14:54
prob.cgi
#!/usr/bin/env python
import urllib,re,random
l = list()
def randprob():
global l
d = ""
if len(l) == 0:
d = urllib.urlopen("http://www.topcoder.com/tc?module=BasicData&c=dd_round_list")
p = re.compile("<full_name>([^<>]*)<\/full_name>")
@shnya
shnya / group.cc
Created May 23, 2011 15:58
grouping
template <class T>
void group2(int j, vector<vector<vector<T> > > &result, vector<bool> &used, vector<T> &path, vector<vector<T> > &path2, const vector<T> &v);
template <class T>
static void group1(vector<vector<vector<T> > > &result, vector<bool> &used, vector<vector<T> > &path2, const vector<T> &v){
int n = v.size();
int unused = -1;
for(int i = 0; i < n; i++){
if(!used[i]) {
unused = i;
@shnya
shnya / gist:922786
Created April 16, 2011 02:22
square sum.
typedef long long int LLI;
#define SZ(x) int(x.size())
#define FOR(x,y,z) for(int x = y; y < z; x++)
#define REP(x,y) FOR(x,0,y)
int main(int argc, char *argv[]){
vector<bool> v(30000000,false);
FOR(i,1,3000){
LLI n = i * i;
@shnya
shnya / combination.cc
Created April 5, 2011 17:54
Permutation and Combination
#include <vector>
#include <iostream>
using namespace std;
void vec_print(const vector<int> &v){
cout << "[ ";
for(vector<int>::const_iterator itr = v.begin();
itr != v.end(); ++itr){
cout << *itr << " ";
@shnya
shnya / SRM 290 Div2 500
Created January 12, 2011 14:52
SRM 290 Div2 500
class BrokenClock
{
vector<string> split(const string &str, const string &delim){
vector<string> res;
size_t current = 0, found, delimlen = delim.size();
while((found = str.find(delim, current)) != string::npos){
res.push_back(string(str, current, found - current));
current = found + delimlen;
}
@shnya
shnya / SRM 290 Div2 250
Created January 12, 2011 14:49
SRM 290 Div2 250
class SpeedTyper
{
public:
string lettersToPractice(string letters, vector <int> times)
{
vector<int> times2;
int ave = 0;
for(size_t i = 0; i < times.size(); i++){
int time = times[i];
if(i != 0)
@shnya
shnya / SRM 344 Div2 Level 2
Created January 4, 2011 17:56
SRM 344 Div2 Level 2
class SimpleRotationDecoder
{
vector<string> split(const string &str, const string &delim){
vector<string> res;
size_t current = 0, found, delimlen = delim.size();
while((found = str.find(delim, current)) != string::npos){
res.push_back(string(str, current, found - current));
current = found + delimlen;
@shnya
shnya / SRM 344 Div2 Level 1
Created January 4, 2011 17:54
SRM 344 Div2 Level 1
class Chessboard
{
public:
string changeNotation(string cell)
{
ostringstream oss;
if(cell[0] >= 'a' && cell[0] <= 'h'){
int c = static_cast<int>(cell[0]) - 'a' + 1;
int n = static_cast<int>(cell[1]) - '1';
@shnya
shnya / file locking test
Created January 2, 2011 17:54
multithread file locking test based on http://kzk9.net/blog/2007/05/flock2.html
#include <sys/file.h>
#include <pthread.h>
#include <assert.h>
#include <semaphore.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
static int locked = 0;
@shnya
shnya / Surrogate Pair Test (For Windows)
Created December 24, 2010 13:49
Surrogate Pair Test (For Windows VC9)
#include "stdafx.h"
#include "Windows.h"
#include "winnls.h"
#include <string>
#include <cstdio>
using namespace std;