Introduction

This is my blog of programming, I take notes and leave codes of computer science problems I solved here. Be my guest to comment :)
Showing posts with label Data Structures. Show all posts
Showing posts with label Data Structures. Show all posts

Thursday, December 17, 2015

UVA 11297 - Census


/*
Problem link
Type: Data Structure - 2D Segment tree/Quad tree.
Algorithm:

Monday, June 17, 2013

Monday, February 25, 2013

Red - black tree full implementation

Red-black tree is known for an efficient data structure use in computer science. It is a type of self-balance binary search tree, it performs insertion, deletion, searching,.. in the worst running time of O(lg n). This is my red-black tree implementation in C++:

Tuesday, December 18, 2012

uva 11995 - I Can Guess the Data Structure!


/*
Problem link
Type: Data structure
*/  
  1  #include <iostream>
  2  #include <cstdio>
  3  #include <cstring>
  4  #include <cmath>
  5  #include <cstdlib>
  6  #include <vector>
  7  #include <queue>
  8  #include <stack>

Saturday, December 15, 2012

uva 10954 - Add All



/*
Problem link
Type: Adhoc - greedy, Data structure - priority queue
*/
 1  #include <iostream>
 2  #include <cstdio>
 3  #include <cstring>
 4  #include <cmath>
 5  #include <vector>
 6  #include <queue>

Thursday, December 13, 2012

Monday, December 10, 2012

uva 11235 - Frequent values



//============================================================================
// Name        : 11235.cpp
// Author      : Mr Tu
// Version     :
// Copyright   : Your copyright notice
// Description : Uva 11235 - Frequent values in C++, Ansi-style
// Problem link
// Algorithm: Data structure - Segment tree
//============================================================================

Sunday, December 9, 2012

uva 11631 - Dark roads


/*
Problem link
Type: Graph
Algorithm: Kruskal, minimum spanning tree, using priority queue
*/
#include <iostream>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <fstream>
using namespace std;
const int maxn = 200010;

Thursday, November 15, 2012

uva 10667 - Largest Block


/*
Problem link
Type: DP, data structure
Algorithm: I use the stack in the problem, with this I can solve it in O(n^2)
 Let h[i][j] be the height of the consecutive comlumn of 0 at (i,j)
 Let l[i][j] is the index left most element of (i,j) that from h[i][l[i][j]] to h[i][j]
  is all >= h[i][j]
 Let r[i][j] is the index right most element of (i,j) that from h[i][j] to h[i][r[i][j]]
  is all >= h[i][j]
 Find max of (j-l[i][j]+r[i][j]-j+1)*h[i][j] for all i,j
 l and r are calculated in O(n^2) by using the stack
*/