Friday, January 4, 2013

Competition Programming Template

In Competition Programming, where speed of solving problems matter, it is good to create a template of useful libraries, commonly used statements like for loops simplified using #define and some typedefs for things like long long, pair<int,int> etc. These make ur coding speed faster as u often have lesser code to type and the resulting code becomes more readable as well. However overuse of such templates might spoil your coding style and make your code unreadable by anyone else. So be wary of their use.
Here is my programming template in C++:
# include <iostream>
# include <fstream>
# include <sstream>
# include <algorithm>
# include <cstdio>
# include <cmath>
# include <numeric>
# include <cstdlib>
# include <cstring>
# include <vector>
# include <list>
# include <set>
# include <map>
# include <stack>
# include <queue>
# include <cctype>
# include <climits>
# include <complex>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,PII> TRI;
typedef vector<string> VS;

#define GI ({int t;scanf("%d",&t);t;})
#define REP(i,a,b) for(int i=a;i<b;i++)
#define FOR(i,n) REP(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define TR(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define bitcount(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define mt(a,b,c) mp(a,mp(b,c))
#define EPS (double)(1e-9)
#define INF 1000000000
#define MOD 1000000007
#define PI (double)(3.141592653589793)

inline int ni()
{
 register int r=0,c;
 for(c=getchar_unlocked();c<=32;c=getchar_unlocked());
 if(c=='-')
  return -ni();
 for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar_unlocked());
 return r;
}

int main()
{
 int t;
 t = ni();
 while(t--) {
  
 }
 return 0;
}
If you are use windows while coding, u might also find it useful to use:
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
to test your code.

No comments:

Post a Comment