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 <vector> | |
#include <list> | |
#include <map> | |
#include <set> | |
#include <queue> | |
#include <deque> | |
#include <stack> | |
#include <bitset> | |
#include <algorithm> | |
#include <functional> |
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
// http://discuss.codechef.com/questions/3292/algorithm-given-an-array-find-all-the-pairs-of-elements-whose-sum-is-k | |
/*For the original problem here is very simple O(N * log N) solution using STL map. | |
Put the array in map: */ | |
map < int, int > cnt; | |
for (int i = 0; i < n; ++i) { | |
cnt[a[i]]++; | |
} |
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
http://sameerbsws.blogspot.in/ | |
http://learn.hackerearth.com/tests/9/ |
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
//When I need to compare double values, I just make a function: | |
int CompareDouble(double a, double b) | |
{ | |
if(a < b - EPS) | |
return -1; | |
if(a > b + EPS) | |
return 1; | |
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
When I need to compare double values, I just make a function: | |
int CompareDouble(double a, double b) | |
{ | |
if(a < b - EPS) | |
return -1; | |
if(a > b + EPS) | |
return 1; | |
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
/* 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", |
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> | |
#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; |
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> | |
#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]; | |
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> | |
#include<conio.h> | |
#include<time.h> | |
void fun() | |
{ | |
printf("fun() starts \n"); | |
printf("Press enter to stop fun \n"); | |
while(1) | |
{ |
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 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; |
OlderNewer