Solved Problems & Ranking (UVa)

Posted in ACM (UVa) Algorithm with tags on February 11, 2009 by Blog Admin

Solved ACM problem (UVa):

Vol: 1 >>> 100, 101, 102, 113, 119, 136, 138, 146, 151, 160.

Vol: 2 >>> 200, 256, 271, 272, 294, 299

Vol: 3 >>> 305, 324, 344, 350, 352, 357, 369, 382, 386, 389, 392, …

Vol: 4 >>> 401, 406, 408, 412, 424, 439, 440, 444, 445, 446, 458, 465, 476, 477, 483, 484, 486, 488, 489, 490, 492, 494, 495, 499

Vol: 5 >>> 516, 530, 532, 541, 543, 572, 575, 576, 579, 591.

Vol: 6 >>> 623, 673, 674, 686, 694.

Vol: 7 >>> 713

Vol: 8 >>> 847, …

Vol: 9 >>> 900, 957, …

Vol: 100 >>> 10004, 10008, 10013, 10018, 10019, 10035, 10038, 10041, 10050, 10055, 10062, 10066, 10070, 10071, 10079, 10082, 10098.

Vol: 101 >>> 10102, 10104, 10106, 10107, 10110, 10127, 10137, 10189, …

Vol: 102 >>> 10220, 10222, 10252, 10260, 10276, 10295, …

Vol: 103 >>> 10300, 10302, 10323, 10327, 10336, 10340, 10346, 10361, 10370.

Vol: 104 >>> 10405, 10409, 10424, 10469, 10473, …

Vol: 105 >>> 10579, 10591, …

Vol: 106 >>> 10664, 10696, 10699

Vol: 107 >>> 10700, 10761, 10783, 10784, 10789, 10790

Vol: 108 >>> 10812, 10852, 10855, …

Vol: 109 >>> 10903, 10921, 10922, 10924, 10929, 10931, 10935, 10945, 10948, 10954, 10970

Vol: 110 >>> 11000, 11040, 11057, 11063, 11074, …

Vol: 111 >>> 11115, 11137, 11150, 11172, 11185, 11192.

Vol: 112 >>> 11219, …

Vol: 113 >>> 11332, 11371, 11389, …

Vol: 114 >>> 11417, 11461, 11462, 11479, 11494, …

Vol: 115 >>> 11520, 11522, 11530, 11541, 11547, 11577.

Vol: 116 >>> 11608, 11614, 11636, …

Vol: 117 >>> 11716, …

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

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 (UVa) : 11716

Posted in ACM (UVa) Algorithm on November 11, 2009 by Blog Admin
// http://uva.onlinejudge.org/external/117/11716.html

#include <stdio.h>
#include <string.h>
#include <math.h>

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

    while ( testCase-- ) {
        char a [10010];

        gets (a);

        int length = strlen (a);
        double square_root = sqrt (length);
        int temp_root = square_root;

        if ( square_root - temp_root != 0 )
            printf ("INVALID");

        else {
            char grid [102] [102];

            int index = 0;

            for ( int i = 0; i < temp_root; i++ ) {
                for ( int j = 0; j < temp_root; j++ )
                    grid [i] [j] = a [index++];
            }

            for ( int i = 0; i < temp_root; i++ ) {
                for ( int j = 0; j < temp_root; j++ )
                    printf ("%c", grid [j] [i]);
            }

        }

        printf ("\n");
    }

    return 0;
}

ACM (UVa) : 10409

Posted in ACM (UVa) Algorithm on November 11, 2009 by Blog Admin
//http://uva.onlinejudge.org/external/104/10409.html

#include <iostream>
using namespace std;

int main ()
{
    int n;

    while ( cin >> n && n ) {

        int top = 1;
        int down = 6;
        int east = 4;
        int west = 3;
        int north = 2;
        int south = 5;
        int temp = 0;

        while ( n-- ) {
            string str;
            cin >> str;

            int x;
            if ( str == "north" )
                x = 0;
            else if ( str == "south" )
                x = 1;
            else if ( str == "west" )
                x = 2;
            else
                x = 3;

            switch (x) {
                case 0 :
                temp = north;
                north = top;
                top = south;
                south = down;
                down = temp;
                break;

                case 1 :
                temp = top;
                top = north;
                north = down;
                down = south;
                south = temp;
                break;

                case 2 :
                temp = top;
                top = east;
                east = down;
                down = west;
                west = temp;
                break;

                case 3 :
                temp = top;
                top = west;
                west = down;
                down = east;
                east = temp;
                break;
            }
        }

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

    return 0;
}

ACM (UVa) : 11371

Posted in ACM (UVa) Algorithm on November 11, 2009 by Blog Admin
// http://uva.onlinejudge.org/external/113/11371.html

#include <stdio.h>
#include <stdlib.h>

int main ()
{
    char a [15];

    while ( scanf ("%s", a) != EOF ) {

        for ( int i = 0; a [i] != 0; i++ ) {
            for ( int j = i + 1; a [j] != 0; j++ ) {
                if ( a [i] < a [j] ) {
                    a [i] ^= a [j];
                    a [j] ^= a [i];
                    a [i] ^= a [j];
                }
            }
        }

        double first = atof (a);

        for ( int i = 0; a [i] != 0; i++ ) {
            for ( int j = i + 1; a [j] != 0; j++ ) {
                if ( a [i] > a [j] ) {
                    a [i] ^= a [j];
                    a [j] ^= a [i];
                    a [i] ^= a [j];
                }
            }
        }

        if ( a [0] == '0' ) {
            for ( int i = 1; a [i] != 0; i++ ) {
                if ( a [i] != '0' ) {
                    a [0] ^= a [i];
                    a [i] ^= a [0];
                    a [0] ^= a [i];
                    break;
                }
            }
        }

        double second = atof (a);

        printf ("%0.lf - %0.lf = %0.lf = 9 * %0.lf\n",
        first, second, first - second, (first - second)/9);

    }

    return 0;
}

The Next Number

Posted in Easy Problems on November 10, 2009 by Blog Admin

General Statement:
A relatively simple task for humans to do is to identify the next number in an arithmetic sequence of numbers. For example, given the sequence of numbers 3, 6, and 9, we know that the next number in the sequence is 12 since each number is followed by a number increasing it by 3. Alternatively, given the sequence of numbers 3, 6, and 12, we know that the next number in the sequence is 24 since each number is followed by a number that doubles it.

Your task is to write a program that will deduce the next integer in a given sequence of three integers where the same arithmetic operation is applied to each integer to produce the next. The only arithmetic operations that will be used are addition, subtraction, multiplication, or division.

Input: The first line of the input contains an integer n that represents the number of data collections that follow where each data collection is on a single line. Each input line contains three integers with each pair of integers separated by a single space. The integers represent a sequence as described in the General Statement.

Output: Your program should produce n lines of output (one for each data collection). The output for each data collection should be the next integer in the corresponding input sequence.

The output is to be formatted exactly like that for the sample output given below.

Assumptions: The value of n will be between 1 and 100, inclusive.
There will be exactly one answer to each input sequence.
The answer will always be an integer (even if division is used).

Sample Input:
3
7 21 35
-10 20 -40
64 16 4

Sample Output:
49
80
1

#include <stdio.h>

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

    while ( n-- ) {
        double x, y, z;

        scanf ("%lf %lf %lf", &x, &y, &z);

        if ( y - x == z - y )
            printf ("%0.lf\n", z + y - x);

        else
            printf ("%0.lf\n", z / (x / y));
    }

    return 0;
}

ACM (UVa) : 11389

Posted in ACM (UVa) Algorithm on November 10, 2009 by Blog Admin
// http://uva.onlinejudge.org/external/113/11389.html

#include <cstdio>
#include <algorithm>
using namespace std;

int main ()
{
    int n;
    int d;
    int r;

    while ( scanf ("%d %d %d", &n, &d, &r) ) {

        if ( !n && !d && !r )
            return 0;

        int morn [102];
        int eve [102];

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

        sort (morn, morn + n);

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

        sort (eve, eve + n);

        int cost = 0;

        for ( int i = 0; i < n; i++ ) {
            int temp = morn [i] + eve [n - i - 1];

            if ( temp > d )
                cost += (temp - d);
        }

        printf ("%d\n", cost * r);

    }

    return 0;
}

ACM (UVa) : 11494

Posted in ACM (UVa) Algorithm on November 9, 2009 by Blog Admin
// http://uva.onlinejudge.org/external/114/11494.html

#include <stdio.h>
#include <stdlib.h>

int main ()
{
    int x1, y1, x2, y2;

    while ( scanf ("%d %d %d %d", &x1, &y1, &x2, &y2) ) {

        if ( x1 == 0 && x2 == 0 && y1 == 0 && y2 == 0 )
            return 0;

        if ( x1 == x2 && y1 == y2 )
            printf ("0\n");

        else if ( x1 == x2 || y1 == y2 )
            printf ("1\n");

        else if ( abs (x1 - x2) == abs (y1 - y2) )
            printf ("1\n");

        else
            printf ("2\n");
    }

    return 0;
}

CodeChef (EASYPROB)

Posted in CodeChef on November 7, 2009 by Blog Admin
http://www.codechef.com/problems/EASYPROB/

137=2(2(2)+2+2(0))+2(2+2(0))+2(0)
1315=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)
73=2(2(2)+2)+2(2+2(0))+2(0)
136=2(2(2)+2+2(0))+2(2+2(0))
255=2(2(2)+2+2(0))+2(2(2)+2)+2(2(2)+2(0))+2(2(2))+2(2+2(0))+2(2)+2+2(0)
1384=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2)+2(2(2)+2(0))+2(2+2(0))
16385=2(2(2+2(0))+2(2)+2)+2(0)

CodeChef (TLG)

Posted in CodeChef on November 7, 2009 by Blog Admin
Question :
http://www.codechef.com/problems/TLG/

Solution :
http://tausiq.wordpress.com/2009/08/27/iarcs-the-lead-game/

CodeChef (INTEST)

Posted in CodeChef on November 7, 2009 by Blog Admin
// http://www.codechef.com/problems/INTEST

#include <stdio.h>

int main ()
{
    int n, k;

    scanf ("%d %d", &n, &k);

    int count = 0;
    int temp;

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

        if ( temp % k == 0 )
            count++;
    }

    printf ("%d\n", count);

    return 0;
}

CodeChef (TEST)

Posted in CodeChef on November 7, 2009 by Blog Admin
// http://www.codechef.com/problems/TEST

#include <iostream>
using namespace std;

int main ()
{
    int n;

    while ( cin >> n && n != 42 )
        cout << n << endl;

    return 0;
}