Online Judges

Posted in Common with tags on February 11, 2009 by Blog Admin

UVa Online Judge :

[ UVa Toolkit ]

Problem set : [ Official site ]

External Problem set:
…/external/[volume number]/[problem number].html
Problem number 100 :[ http://uva.onlinejudge.org/external/1/100.html ]

Volume wise Problem set:
…vol=[volume number]
For volume 1 :[ http://online-judge.uva.es/problemset/volume.php?vol=1 ]

Hints : [ Algorithmist ] & [ Steven Halim ]

[ Tools ]

[ Hunting Problems ]

[ Problem Rank list ]

Total Solved: 176
Ranking: 1917 [not updated] [ Page ]
UVa online judge user id: 31371


Usaco :

[ Training ]
[ Contest ]
[ Forum ]


CodeChef :

[ Official site ]


TJU Online Judge :

[ Official site ]

Total Solved : 92
Rank : 614 [not updated] [ Page ]


TopCoder :

[ Official site ]


IARCS :

Indian National Olympiad in Informatics

[ Problems ]

Test Data Given. Some solution can be found of particular problem.


Project Euler :

series of challenging mathematical/computer programming problems. After solving a problem, a discussion forum of respective problem will be opened.

[ Official site ]

Statistics : [ Bangladesh ]

Total Solved : 73


Sphere Online Judge :

[ Official site ]


Code Jam :

[ Official site ]

[ Source code ]


Saratov Online Judge :

[ Official site ]


Croatian Open Competition in Informatics :

[ Officail site ]

High School Programming Contest.
Test data + Sample solutions + Editorials are available of previous contests.


Favorite Site/Blog :

[ Smilitude ]

[ Young Programmer ]

[ Come on Code on ]

[ Ruet Programmer ]

[ Harsh ]

[ Puzzle ]

[ Quote ]

[ Php Tutorial ]

[ C/C++/Java/Bash/Asm Arena ]

Java Script Tutorial : [ Echo ] [ learn js ]

[ Cut the Knot ]

[ Combinatorial Game Theory ]

Download Links of Some Essential Books:
!!! [ Introduction to Algorithms. ]
!!! [ Programming Challenges. ]
!!! [ Art of Programming Contest. ] [Elementary Level]
!!! [ Some Web-site Links ] by Saidul Islam

ACM (TJU) : 2123

Posted in ACM (TJU) on December 11, 2009 by Blog Admin
#include <stdio.h>

int main ()
{
    int n;
    int input;

    while ( scanf ("%d", &n) && n ) {
        int john = 0;

        for ( int i = 0; i < n; i++ ) {
            scanf ("%d", &input);
            if ( input )
                john++;
        }

        printf ("Mary won %d times and John won %d times\n", n - john, john);
    }

    return 0;
}

ACM (TJU) : 1031

Posted in ACM (TJU) on December 11, 2009 by Blog Admin
#include <stdio.h>
#include <string.h>

int main ()
{
    int s;
    char number [10];

    while ( scanf ("%d %s", &s, number) ) {
        if ( s == 0 && strcmp (number, "0") == 0 )
            return 0;

        // 1st line
        for ( int i = 0; number [i] != 0; i++ ) {
            if ( i )
                printf (" ");

            switch (number [i] - '0') {
                case 1 :
                case 4 :
                    for ( int j = 0; j < s + 2; j++ )
                        printf (" ");
                    break;
                default :
                    printf (" ");
                    for ( int j = 0; j < s; j++ )
                        printf ("-");
                    printf (" ");
            }
        }
        printf ("\n");

        // 1st vertical
        for ( int line = 0; line < s; line++ ) {
            for ( int i = 0; number [i] != 0; i++ ) {
                if ( i )
                    printf (" ");
                // left
                switch (number [i] - '0') {
                    case 1 :
                    case 2 :
                    case 3 :
                    case 7 :
                        printf (" ");
                        break;
                    default :
                        printf ("|");
                }

                // right
                switch (number [i] - '0') {
                    case 5 :
                    case 6 :
                        for ( int j = 0; j <= s; j++ )
                            printf (" ");
                        break;
                    default :
                        for ( int j = 0; j < s; j++ )
                            printf (" ");
                        printf ("|");
                }
            }

            printf ("\n");
        }

        // 2nd horizontal
        for ( int i = 0; number [i] != 0; i++ ) {
            if ( i )
                printf (" ");

            switch (number [i] - '0') {
                case 1 :
                case 7 :
                case 0 :
                    for ( int j = 0; j < s + 2; j++ )
                        printf (" ");
                    break;
                default :
                    printf (" ");
                    for ( int j = 0; j < s; j++ )
                        printf ("-");
                    printf (" ");
            }
        }
        printf ("\n");

        // 2nd vertical
        for ( int line = 0; line < s; line++ ) {
            for ( int i = 0; number [i] != 0; i++ ) {
                if ( i )
                    printf (" ");
                // left
                switch (number [i] - '0') {
                    case 1 :
                    case 3 :
                    case 4 :
                    case 5 :
                    case 7 :
                    case 9 :
                        printf (" ");
                        break;
                    default :
                        printf ("|");
                }

                // right
                switch (number [i] - '0') {
                    case 2 :
                        for ( int j = 0; j <= s; j++ )
                            printf (" ");
                        break;
                    default :
                        for ( int j = 0; j < s; j++ )
                            printf (" ");
                        printf ("|");
                }
            }

            printf ("\n");
        }

        // 3rd horizon
        for ( int i = 0; number [i] != 0; i++ ) {
            if ( i )
                printf (" ");

            switch (number [i] - '0') {
                case 1 :
                case 4 :
                case 7 :
                    for ( int j = 0; j < s + 2; j++ )
                        printf (" ");
                    break;
                default :
                    printf (" ");
                    for ( int j = 0; j < s; j++ )
                        printf ("-");
                    printf (" ");
            }
        }
        printf ("\n\n");
    }

    return 0;
}

ACM (TJU) : 1279

Posted in ACM (TJU) on December 11, 2009 by Blog Admin
#include <cstdio>
#include <algorithm>
using namespace std;

int main ()
{
    int dataset;
    scanf ("%d", &dataset);

    while ( dataset-- ) {
        int n;
        scanf ("%d", &n);

        int a [1005];

        for ( int i = 0; i < n; i++ )
            scanf ("%d", & a [i]);

        sort (a, a + n);

        int max = 0;
        for ( int i = n - 1; i >= 0; i-- ) {
            int temp = a [i] * (n - i);
            if ( temp >= max )
                max = temp;
        }
        printf ("%d\n", max);
    }

    return 0;
}

ACM (TJU) : 1112

Posted in ACM (TJU) on December 11, 2009 by Blog Admin
import java.math.BigInteger;
import java.util.Scanner;

/**
 * @author Md. Shahab Uddin
 * Id : 014081002
 * Dept : CTE, UIU
 */
public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner (System.in);

        BigInteger number;
        BigInteger result = BigInteger.ZERO;

        while ( input.hasNextBigInteger() ) {
            number = input.nextBigInteger();
            result = result.add(number);
        }

        System.out.println (result);
    }

}

ACM (TJU) : 1630

Posted in ACM (TJU) on December 11, 2009 by Blog Admin
#include <stdio.h>
#include <string.h>

char a [1000];
char b [1000];
int len_a;
int len_b;

int commonA (int x)
{
    int count = 0;

    for ( int i = x, j = 0; i < len_a; i++, j++ ) {
        if ( j < len_b && a [i] == b [j] )
            count++;
    }

    return count;
}

int commonB (int x)
{
    int count = 0;

    for ( int i = x, j = 0; i < len_b; i++, j++ ) {
        if ( j < len_b && b [i] == a [j] )
            count++;
    }

    return count;
}

int GCD (int x, int y)
{
    if ( y == 0 )
        return x;
    return GCD (y, x % y);
}

int main ()
{
    while ( scanf ("%s", a) ) {
        if ( !strcmp (a, "-1") )
            return 0;

        scanf ("%s", b);

        len_a = strlen (a);
        len_b = strlen (b);
        int max = 0;

        for ( int i = 0; a [i] != 0; i++ ) {
            int temp = commonA (i);
            if ( temp > max )
                max = temp;
        }

        for ( int i = 0; b [i] != 0; i++ ) {
            int temp = commonB (i);
            if ( temp > max )
                max = temp;
        }

        int total_len = len_a + len_b;
        int gcd = GCD (max * 2, total_len);
        int nomin = (max * 2) / gcd;
        int domin = total_len / gcd;

        if ( nomin == 0 || (nomin == 1 && domin == 1) )
            printf ("appx(%s,%s) = %d\n", a, b, nomin);
        else
            printf ("appx(%s,%s) = %d/%d\n", a, b, nomin, domin);

    }

    return 0;
}

ACM (TJU) : 1412

Posted in ACM (TJU) on December 11, 2009 by Blog Admin
#include <stdio.h>

int main ()
{
    int c;
    scanf ("%d", &c);

    while ( c-- ) {
        int n;
        scanf ("%d", &n);

        int number [1005];
        int sum = 0;

        for ( int i = 0; i < n; i++ ) {
            scanf ("%d", &number [i]);
            sum += number [i];
        }

        double avg = sum / (double) n;

        int count = 0;

        for ( int i = 0; i < n; i++ ) {
            if ( avg < number [i] )
                count++;
        }

        printf ("%.3lf%%\n", ( count / (double) n ) * 100);
    }

    return 0;
}

ACM (TJU) : 1088

Posted in ACM (TJU) on December 11, 2009 by Blog Admin
#include <cstdio>
#include <algorithm>
using namespace std;

struct node {
    int x;
    int y;
    int nut;
} a [2550];

bool cmp (node p, node q)
{
    return p.nut > q.nut;
}

int main ()
{
    int dataset;
    scanf ("%d", &dataset);

    while ( dataset-- ) {
        int m, n, k;
        scanf ("%d %d %d", &m, &n, &k);

        int field [52] [52];
        int index = 0;

        for ( int i = 0; i < m; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                scanf ("%d", &field [i] [j]);

                if ( field [i] [j] ) {
                    a [index].nut = field [i] [j];
                    a [index].x = i;
                    a [index].y = j;
                    index++;
                }
            }
        }

        sort (a, a + index, cmp);

        int totalNut = 0;
        int cur_x = 0;
        int cur_y = a [0].y;
        k--;

        for ( int i = 0; i < index; i++ ) {
            int inCost = abs (cur_x - a [i].x) + abs (cur_y - a [i].y) + 1;
            int outCost = abs (0 - a [i].x) + 1;
            int tempCost = inCost + outCost;

            if ( tempCost <= k ) {
                k -= inCost;
                cur_x = a [i].x;
                cur_y = a [i].y;
                totalNut += a [i].nut;
            }

            else
                break;
        }

        printf ("%d\n", totalNut);
    }

    return 0;
}

ACM (UVa) : 739

Posted in ACM (UVa) Algorithm on December 9, 2009 by Blog Admin
#include <stdio.h>
#include <string.h>

int soundexcode (char x)
{
    char array1 [] = "AEIOUYWH";
    if ( strchr (array1, x) )
        return 0;

    char array2 [] = "BPFV";
    if ( strchr (array2, x) )
        return 1;

    char array3 [] = "CSKGJQXZ";
    if ( strchr (array3, x) )
        return 2;

    if ( x == 'D' || x == 'T' )
        return 3;

    if ( x == 'L' )
        return 4;

    if ( x == 'M' || x == 'N' )
        return 5;

    if ( x == 'R' )
        return 6;
}

int main ()
{
    printf ("         NAME                     SOUNDEX CODE\n");

    char name [25];

    while ( gets (name) ) {
        char output [25];
        output [0] = name [0];
        output [1] = output [2] = output [3] = '0';

        int code = soundexcode (name [0]);
        int index = 1;
        int length = strlen (name);

        for ( int i = 1; i < length; i++ ) {
            int temp_code = soundexcode (name [i]);

            if ( temp_code != code && temp_code != 0 )
                output [index++] = temp_code + '0';

            if ( temp_code != code )
                code = temp_code;
        }

        printf ("%9s%s", "", name);
        for ( int i = 0; i < 25 - length; i++ )
            printf (" ");
        printf ("%c%c%c%c\n", output [0], output [1],
        output [2], output [3]);

    }

    printf ("                   END OF OUTPUT\n");

    return 0;
}

ACM (UVa) : 740

Posted in ACM (UVa) Algorithm on December 9, 2009 by Blog Admin
#include <stdio.h>
#include <string.h>

char down_shift (char x [])
{
    if ( strcmp ("00000", x) == 0 )
        return '<';
    if ( strcmp ("00001", x) == 0 )
        return 'T';
    if ( strcmp ("00010", x) == 0 )
        return '*';
    if ( strcmp ("00011", x) == 0 )
        return 'O';
    if ( strcmp ("00100", x) == 0 )
        return ' ';
    if ( strcmp ("00101", x) == 0 )
        return 'H';
    if ( strcmp ("00110", x) == 0 )
        return 'N';
    if ( strcmp ("00111", x) == 0 )
        return 'M';
    if ( strcmp ("01000", x) == 0 )
        return '=';
    if ( strcmp ("01001", x) == 0 )
        return 'L';
    if ( strcmp ("01010", x) == 0 )
        return 'R';
    if ( strcmp ("01011", x) == 0 )
        return 'G';
    if ( strcmp ("01100", x) == 0 )
        return 'I';
    if ( strcmp ("01101", x) == 0 )
        return 'P';
    if ( strcmp ("01110", x) == 0 )
        return 'C';
    if ( strcmp ("01111", x) == 0 )
        return 'V';
    if ( strcmp ("10000", x) == 0 )
        return 'E';
    if ( strcmp ("10001", x) == 0 )
        return 'Z';
    if ( strcmp ("10010", x) == 0 )
        return 'D';
    if ( strcmp ("10011", x) == 0 )
        return 'B';
    if ( strcmp ("10100", x) == 0 )
        return 'S';
    if ( strcmp ("10101", x) == 0 )
        return 'Y';
    if ( strcmp ("10110", x) == 0 )
        return 'F';
    if ( strcmp ("10111", x) == 0 )
        return 'X';
    if ( strcmp ("11000", x) == 0 )
        return 'A';
    if ( strcmp ("11001", x) == 0 )
        return 'W';
    if ( strcmp ("11010", x) == 0 )
        return 'J';
    if ( strcmp ("11100", x) == 0 )
        return 'U';
    if ( strcmp ("11101", x) == 0 )
        return 'Q';
    if ( strcmp ("11110", x) == 0 )
        return 'K';
}

char up_shift (char x [])
{
    if ( strcmp ("00000", x) == 0 )
        return '>';
    if ( strcmp ("00001", x) == 0 )
        return '5';
    if ( strcmp ("00010", x) == 0 )
        return '@';
    if ( strcmp ("00011", x) == 0 )
        return '9';
    if ( strcmp ("00100", x) == 0 )
        return ' ';
    if ( strcmp ("00101", x) == 0 )
        return '%';
    if ( strcmp ("00110", x) == 0 )
        return ',';
    if ( strcmp ("00111", x) == 0 )
        return '.';
    if ( strcmp ("01000", x) == 0 )
        return '+';
    if ( strcmp ("01001", x) == 0 )
        return ')';
    if ( strcmp ("01010", x) == 0 )
        return '4';
    if ( strcmp ("01011", x) == 0 )
        return '&';
    if ( strcmp ("01100", x) == 0 )
        return '8';
    if ( strcmp ("01101", x) == 0 )
        return '0';
    if ( strcmp ("01110", x) == 0 )
        return ':';
    if ( strcmp ("01111", x) == 0 )
        return ';';
    if ( strcmp ("10000", x) == 0 )
        return '3';
    if ( strcmp ("10001", x) == 0 )
        return '"';
    if ( strcmp ("10010", x) == 0 )
        return '$';
    if ( strcmp ("10011", x) == 0 )
        return '?';
    if ( strcmp ("10100", x) == 0 )
        return '#';
    if ( strcmp ("10101", x) == 0 )
        return '6';
    if ( strcmp ("10110", x) == 0 )
        return '!';
    if ( strcmp ("10111", x) == 0 )
        return '/';
    if ( strcmp ("11000", x) == 0 )
        return '-';
    if ( strcmp ("11001", x) == 0 )
        return '2';
    if ( strcmp ("11010", x) == 0 )
        return '\'';
    if ( strcmp ("11100", x) == 0 )
        return '7';
    if ( strcmp ("11101", x) == 0 )
        return '1';
    if ( strcmp ("11110", x) == 0 )
        return '(';
}

int main ()
{
    char down [35];
    gets (down);

    char up [35];
    gets (up);

    char input [85];

    while ( gets (input) ) {
        int length = strlen (input);

        bool flag_down = true;

        for ( int i = 0; i < length; i += 5 ) {
            char temp [6];

            temp [0] = input [i];
            temp [1] = input [i + 1];
            temp [2] = input [i + 2];
            temp [3] = input [i + 3];
            temp [4] = input [i + 4];
            temp [5] = 0;

            if ( strcmp (temp, "11111") == 0 )
                flag_down = false;
            else if ( strcmp (temp, "11011") == 0 )
                flag_down = true;
            else {
                if ( flag_down )
                    printf ("%c", down_shift (temp));

                else
                    printf ("%c", up_shift (temp));
            }
        }

        printf ("\n");
    }

    return 0;
}

ACM (UVa) : 748

Posted in ACM (UVa) Algorithm on December 7, 2009 by Blog Admin
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int convert (char r [])
{
    int dot;
    int length = strlen (r);

    for ( int i = 0; i < length; i++ ) {
        if ( r [i] == '.' )
            dot = i;
    }

    for ( int i = dot; i < length - 1; i++ )
        r [i] = r [i + 1];

    r [length - 1] = 0;

    return atoi (r);
}

int main ()
{
    char input [12];

    while ( gets (input) ) {
        char r [8];
        int n;

        sscanf (input, "%s %i", r, &n);

        int result [100];
        int r_length = strlen (r);
        int index = 0;
        int dot_position;

        while ( r [index] == '0' ) { // leading zero
            for ( int i = index + 1; r [i] != 0; i++ )
                r [i - 1] = r [i];
            r [r_length - index - 1] = 0;
            r_length--;
        }

        index = 0;

        while ( r [r_length - 1] == '0' ) { // trailing zero
            r [r_length - 1] = 0;
            r_length--;
        }

        for ( int i = r_length - 1; i >= 0; i-- ) {
            if ( r [i] == '.' )
                dot_position = r_length - i - 1;
            else
                result [index++] = r [i] - '0';
        }

        int carry;
        int number = convert (r);
        int j;

        for ( int i = 1; i < n; i++ ) {
            carry = 0;
            for ( j = 0; j < index; j++ ) {
                carry = result [j] * number + carry;
                result [j] = carry % 10;
                carry /= 10;
            }

            while ( carry ) {
                result [j++] = carry % 10;
                carry /= 10;
            }

            index = j;
        }

        dot_position *= n;
        dot_position = index - dot_position;

        while ( dot_position < 0 ) {
            result [index++] = 0;
            dot_position++;
        }

        for ( int i = index - 1; i >= 0; i-- ) {
            if ( dot_position-- == 0 )
                printf (".");
            printf ("%d", result [i]);
        }
        printf ("\n");
    }

    return 0;
}