This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int max(int a,int b) | |
{ | |
return ( ( a + b ) + abs( a – b ) ) / 2; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
def sub_sort(array,low,high): | |
key = array[low] | |
while low < high: | |
while low < high and array[high] >= key: | |
high -= 1 | |
while low < high and array[high] < key: | |
array[low] = array[high] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
MAX_COIN = 200 | |
arr = [i * 0 for i in range(201)] | |
arr[0] = 1 | |
for coin in [1,2,5,10,20,50,100,200]: | |
j = coin | |
while j <= MAX_COIN: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define N (1<<22)+200 | |
long long prime[N]; | |
void get_prime() | |
{ | |
memset(prime,0,sizeof(prime)); | |
for(int i=2;i<N;i++) | |
{ | |
if(prime[i]==0) prime[++prime[0]]=i; | |
for(int j=1;j<=prime[0]&&(i*prime[j]<N);j++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
from is_prime import is_prime | |
prime = [i * 0 for i in range(1000)] | |
prime[0] = 1 | |
prime[1] = 2 | |
prime[2] = 3 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
from sys import argv | |
from math import sqrt | |
def is_prime(num): | |
s = sqrt(num) | |
step = 4 | |
if num <= 3: | |
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
long a=10000,b,c=2800,d,e,f[2801],g; | |
int main() { | |
for(;b-c;) f[b++]=a/5; | |
for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a) | |
for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TrieNode { | |
unsigned char v; | |
struct TrieNode* children[26]; | |
}; | |
#define CACHE_SIZE 100000 | |
static struct TrieNode node_cache[CACHE_SIZE]; | |
static int used_cache_size = 0; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrieNode(object): | |
# Initialize your data structure here. | |
def __init__(self): | |
self.count = 0 | |
self.children = {} | |
class Trie(object): | |
def __init__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Send UDP broadcast packets | |
MYPORT = 50000 | |
import sys, time | |
from socket import * | |
s = socket(AF_INET, SOCK_DGRAM) | |
s.bind(('', 0)) | |
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) |