IARCS (The Lazy Circus Gymnast)


// Q : http://www.iarcs.org.in/inoi/contests/nov2004/Basic-1.php

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

struct node {
    int index;
    int value;
} a [5005];

bool compare (node i, node j)
{
    return i.value < j.value;
}

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

    for ( int i = 0; i < n; i++ ) {
        a [i].index = i + 1;
        scanf ("%d", & a [i].value);
    }

    sort (a, a + n, compare);

    for ( int i = 0; i < n; i++ )
        printf ("%d\n", a [i].index);

    return 0;
}
Advertisements

IARCS (A Board Game)



/* Question:
http://www.iarcs.org.in/inoi/contests/oct2004/Basic-2.php
Author : Tausiq */

#include <stdio.h>

int main ()
{
    int N, M;
    scanf ("%i %i", &N, &M);

    char N_array [10005];

    for ( int i = 1; i <= N; i++ ) {
        char temp;

        while ( scanf ("%c", &temp) ) {
            if ( temp == '+' || temp == '-' )
                break;
        }

        N_array &#91;i&#93; = temp;
    }

    int j = 1; // token
    int d; // dice
    int count = 1;

    for ( int i = 0; i < M; i++ ) {
        scanf ("%i", &d);

        if ( N_array &#91;j&#93; == '+' && j + d <= N )
            j += d;

        else if ( N_array &#91;j&#93; == '-' && j - d >= 1 )
            j -= d;

        if ( j == 1 )
            count++;
    }

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

    return 0;
}

IARCS (BCCS Elections)



/* Question:
http://www.iarcs.org.in/inoi/contests/oct2004/Basic-1.php
Author : Tausiq */

#include <stdio.h>

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

    int array [10002];

    for ( int i = 1; i <= C; i++ )
        array &#91;i&#93; = 0;

    for ( int i = 1; i <= N; i++ ) {
        int choice;
        scanf ("%d", &choice);
        array &#91;choice&#93;++;
    }

    int max = 0;
    int index;

    for ( int i = 1; i <= C; i++ ) {
        if ( array &#91;i&#93; > max ) {
            max = array [i];
            index = i;
        }
    }

    array [index] = 0;

    int max_2nd = 0;

    for ( int i = 1; i <= C; i++ ) {
        if ( array &#91;i&#93; > max_2nd ) {
            max_2nd = array [i];
            index = i;
        }
    }

    array [index] = 0;

    int max_3rd = 0;

    for ( int i = 1; i <= C; i++ ) {
        if ( array &#91;i&#93; > max_3rd ) {
            max_3rd = array [i];
            index = i;
        }
    }
    printf ("%d\n", index);

    return 0;
}

IARCS (The Lead Game)



/* Question:
http://www.iarcs.org.in/inoi/contests/sep2004/Basic-2.php
Author : Tausiq */

#include <stdio.h>

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

    int player_1 = 0;
    int player_2 = 0;
    int lead;
    int max_lead = 0;
    int lead_player;
    int winner;

    while ( N-- ) {

        int S, T;
        scanf ("%d %d", &S, &T);

        player_1 += S;
        player_2 += T;

        lead = player_1 - player_2;
        lead_player = 1;

        if ( lead < 0 ) {
            lead *= -1;
            lead_player = 2;
        }

        if ( lead > max_lead ) {
            max_lead = lead;
            winner = lead_player;
        }
    }

    printf ("%d %d\n", winner, max_lead);
    return 0;
}

IARCS (Prime Palindromes)


Question :
http://www.iarcs.org.in/inoi/contests/sep2004/Basic-1.php

Solutions :


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

bool is_prime (int x)
{
    int length = (int) sqrt (x);

    for ( int i = 2; i <= length; i++ ) {
        if ( x % i == 0 )
            return false;
    }

    return true;
}

bool is_palindorme (int x)
{
    char a [8];
    sprintf (a, "%d", x);

    int length = strlen (a);

    for ( int i = 0; i < length / 2; i++ ) {
        if ( a [i] != a [length - 1 - i] )
            return false;
    }

    return true;
}

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

    if ( N % 2 == 0 ) // N even
        N++;

    while( true ) {
        if ( is_palindorme (N) && is_prime (N) ) {
            printf ("%d\n", N);
            break;
        }

        N += 2;
    }
    return 0;
}