Saturday, February 5, 2011

Getting started with USACO



USACO (or United States of America Coding Olympiad) is a programming competition primarily for students in USA. It allows codes to be written in c, c++, java and pascal programming languages. There are currently three divisions of the USACO: Bronze (easiest but requires some programming ability), Silver, and Gold (hardest). Participants advance through the divisions by performing well in their current division, or in a qualifying round.

Training pages, internet competitions, US Open ( please don't confuse it with the grand slam :P ) form the basic three parts of USACO. Of these three - training pages are of our interest. These pages are designed to develop one's skills in programming solutions to difficult and varied algorithmic problems at one's own pace. In addition to around several problems, there are texts on programming techniques such as greedy algorithms, dynamic programming, shortest path and many more. Enthusiasts find the training pages so useful that people from other countries use them to prepare for their own national or international level competitions. Amazing thing is that today the coders from other countries have out numbered the US participants !! :P

For getting started with USACO you can register by clicking here. After the registration you can begin with the chapters and corresponding sections through the USACO gateway. The submissions at USACO must conform by following rules:
  • All solutions must have a header as follows:
/*
ID: YourId
PROG: the name of program which will be provided in the problem statement itself
LANG: preferred language
*/
  • The input needs to be read from a file named PROG.in (PROG refers to name of the program as mentioned in header) and output written onto another file named PROG.out.
  • The output file must have a whitespace at the end else it will not compile.

Here's my solution to a problem named Dual Palindromes:

/*

ID: vaibhav4

PROG: dualpal

LANG: C++

*/


#include<fstream>

#include<iostream>

using namespace std;

int isPal(string a)

{

 int i,j;

 for(i=0,j=a.size()-1;i<j;i++,j--)

     if(a[i]!=a[j]) return 0;

 return 1;

}

string conv(int decimal, int base)

{

 if(decimal == 0) return "0";

 char NUMS[] = "0123456789ABCDEFGHIJ";

 string result = "";

 do

 {

     result.push_back(NUMS[decimal%base]);

     decimal /= base;

 }while(decimal != 0);



 return string(result.rbegin(), result.rend());

}

int main()

{

 ifstream cin("dualpal.in");

 ofstream cout("dualpal.out");

 int s,n,i,count=0,count1=0;

 cin>>n>>s;

 s++;

 while(count!=n)

 {

     count1=0;

     for(i=2;i<=10;i++)

     {

         if(isPal(conv(s,i)))

             count1++;

         if(count1>=2)

         {

             cout<<s<<"\n";

             count++;

             break;

         }

     }

     s++;

 }

 return 0;

}

Hope it's now easy to get started with USACO..
Happy Coding !!

* * * * *

1 comment:

  1. This is one of the important post.By read your post I got a fantastic idea about programming language.This is one of the pretty information.
    Android app developers

    ReplyDelete