Skip to content

Instantly share code, notes, and snippets.

View sumanth232's full-sized avatar

Sumanth Bandi sumanth232

View GitHub Profile
@sumanth232
sumanth232 / templateCodeforces.cpp
Last active September 11, 2015 19:32
Codeforces Template
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
@sumanth232
sumanth232 / Fib.cpp
Last active August 29, 2015 14:02
Find Fibonacci number using Matrix exponentiation -> O(log n)
// used this code at http://www.spoj.com/problems/FIBOSUM/
#define ll long long
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< vector<int> > vvi;
typedef vector< vll > vvll;
@sumanth232
sumanth232 / nChooseR.cpp
Last active August 29, 2015 14:02
N Choose R
#include<algorithm>
long long Choose(long long n, long long r)
{
if(r>n) return 0;
/* nCr = nCn-r
very important -> reduces lot of time of computation */
r = min(r,n-r);
if(r==0) return 1;
@sumanth232
sumanth232 / git.txt
Created November 8, 2013 08:29
learn github branching tutorial
http://pcottle.github.io/learnGitBranching/index.html
@sumanth232
sumanth232 / SMO.c
Created October 31, 2013 21:00
Platt SMO algo implementation
#include <iostream>
#include <fstream>
#include <strstream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
@sumanth232
sumanth232 / modpower.c
Last active December 25, 2015 03:59
a^b % mod
#define mod 1000000007LL
typedef long long ll;
ll power(ll a, ll b)
{
ll result = 1;
while (b){
if (b&1){ // if(b%2 == 1)
result = ((result % mod) * (a % mod)) % mod;
@sumanth232
sumanth232 / measurement_of_time.c
Created September 29, 2013 08:35
Measure the time of a function in seconds
#include<stdio.h>
#include<conio.h>
#include<time.h>
void fun()
{
printf("fun() starts \n");
printf("Press enter to stop fun \n");
while(1)
{
@sumanth232
sumanth232 / max_subarray_sum.c
Created August 24, 2013 12:22
Finds the maximum contiguous sum in an array
#include <stdio.h>
#include <stdlib.h>
int max_subarray_sum(int a[],int size)
{
int i;
int cumulative_sum = a[0];
int maxsofar = a[0];
int cumulative_min = a[0];
@sumanth232
sumanth232 / split_string.c
Last active December 20, 2015 14:39
split function in C ( written by myself )
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define len 200
typedef struct _string
{
char tokens[30][200]; // tokens can be treated as an array of strings
int no_of_tokens;
@sumanth232
sumanth232 / Suffix_Array.cpp
Created July 10, 2013 12:56
1) Suffix Array construction using - Manber Myers algorithm in O(n log n) time ( O(n) - Karkkainan Sander's algorithm also there ) 2) Linear-Time Longest-Common-Prefix Computation in Suffix
/* By the author :
I'd recommend reading the paper "Linear-Time Longest-Common-Prefix Computation in Suffix Arrays and Its Applications" by Toru Kasai, Gunho Lee, Hiroki Arimura, Setsuo Arikawa, and Kunsoo Park.
It shows how to find the length of the longest common prefixes between consecutive suffixes in lineal time, in around 10 lines of code (really, see code in edit).
I also wanted to share my implementation of Manber & Myers algorithm which is also on edit. I got Accepted on SUBST1 with it. */
// Begins Suffix Arrays implementation
// O(n log n) - Manber and Myers algorithm
// Refer to "Suffix arrays: A new method for on-line string searches",