Skip to content

Instantly share code, notes, and snippets.

View GnsP's full-sized avatar
👽
avant-garde

Ganesh Prasad GnsP

👽
avant-garde
View GitHub Profile
@GnsP
GnsP / SUBGCD.cpp
Last active August 29, 2015 14:21
SUBARRAY GCD
#include <iostream>
using namespace std;
long long gcd(long long a, long long b){ // Find the GCD of two numbers using euclidian algorithm
if(b==0) return a;
return gcd(b, a%b);
}
int main(){
long long T, N, x, g;
@GnsP
GnsP / TICKETS5.cpp
Created May 21, 2015 13:28
TICKETS (Codechef parctice)
#include <cstdio>
using namespace std;
bool dfa(){ // Check what a DFA (Deterministic Finite Automaton) is and how it works.
int state = 0; // DFAs are a bit complex for beginners, because it's an abstract mathematical
char a = getchar(); // concept. But on the other hand the logic used for this specific problem
char b = getchar(); // is very basic. Hence just the basic idea of the DFA concept should suffice.
if(a==b) state = 2;
char ch;
while((ch=getchar()) != '\n'){
@GnsP
GnsP / TWSTR.cpp
Created May 26, 2015 15:54
This is probably the most abstract piece of memory consuming shit I've ever written. And holy crap, it got accepted in the 1st attempt itself :o
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
@GnsP
GnsP / boiler.cpp
Created May 30, 2015 04:27
Competitive Coding Boilerplate
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
@GnsP
GnsP / css_validator.py
Created June 6, 2015 13:09
CSS Validator
#!/usr/bin/env python
'''
CSS Validator Automation Script
*******************************
Validates all css files in a given directory and writes
errors and warnings to log files in a separate directory.
Ganesh Prasad Sahoo (c) 2015
@GnsP
GnsP / spoj_farida.cpp
Last active August 29, 2015 14:24
Princess Farida (DP Problem from SPOJ)
/*
* This is the solution to problem 'Princess Farida' on SPOJ. Link : http://www.spoj.com/problems/FARIDA/
*
* The problem can be solved using Dynamic Programming, the recurrence
* relation for the DP is :
* DP[i] = INPUT[i] + MAX( DP[i-2], DP[i-3] ) ... Think yourself 'why ?'
*
* Now, as we see that the DP requires only upto 3rd previous term, we can
* minimize the storage required to 4 values only and use a cyclic array
* for the DP. Carefully study the solution to see how.
@GnsP
GnsP / ATOMS.cpp
Last active August 29, 2015 14:24
Breaking Into Atoms (Codechef Practice Problem)
/*
* *WARNING*
* If you are not familiar with bit manipulations and bitwise programming
* go study them first.
*
**************************************************************************
*
* This is the solution to the practice problem 'Breaking into Atoms'
* on Codechef. Link to problem : http://www.codechef.com/problems/ATOMS
*
@GnsP
GnsP / modular.hpp
Created August 4, 2015 09:55
Modular Arithmatic Suit
#ifndef NETSEC_MODULAR_HPP_INCLUDED__
#define NETSEC_MODULAR_HPP_INCLUDED__
class modularInverseException: public std::exception{
virtual const char *what() const throw(){
return "Modular Inverse does not exist in this case.";
}
} modularInverseDoesNotExist;
template<int Mod>
@GnsP
GnsP / modularTest.cpp
Created August 4, 2015 09:56
test file for modular arithmatic suit
#include <iostream>
#include "modular.hpp"
using namespace std;
int main(){
modular<7> a,b,c,d;
a=3;
b=8;
c=-5;
cout<<a()<<" "<<b()<<" "<<c()<<endl; // expected 3 1 2
tree = [0 for x in range(1000)]
def countNodes(root):
pass
def addChildren(children, parent):
tree[parent<<1] = children[0]
tree[parent<<1|1] = children[1]