Friday, June 10, 2011

11530 - SMS Typing


782 - Contour Painting


784 - Maze Exploration


785 - Grid Colouring


852 - Deciding victory in Go


Monday, June 6, 2011

10420 - List of Conquests


10363 - Tic Tac Toe


941 - Permutations


661 - Blowing Fuses


10683 - The decadary watch


11616 - Roman Numerals


11498 - Division of Nlogonia


377 - Cowculations


11223 - O: dah dah dah!


Sunday, June 5, 2011

394 - Mapmaker

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

char NAME[20][20];
int BA[20],W[20],D[30];
int DIM[20][40],Index,pos[30];

int calculate();

main()  {
  
    int i,j,k,name,test,lim;
    char ARRAY[15];
    //freopen("in.txt","r",stdin);
  
    scanf("%d%d", &name, &test);
  
    for(i = 0; i<name; i ++)
    {
        scanf("%s%d%d%d",NAME[i], &BA[i], &W[i], &D[i]);
        lim = D[i]<<1;;
        for(j = 0; j < lim; j ++)
            scanf("%d", &DIM[i][j]);
    }
  
    for(i = 0; i<test; i ++)
    {
        scanf("%s",ARRAY);
        for(j = 0; j<name;  j ++)
            if(!strcmp(ARRAY,NAME[j]))
                break;
        k = D[j];
        Index = j;
        for(j = 0; j<k; j ++)
            scanf("%d", &pos[j]);
        calculate();
    }
    return 0;
}

int calculate()
{
  
    int i,j,k,m,L[30],pos_1[20],lim;
    int address;
  
    k = D[Index];
    m = 0;
    lim = k<<1;
  
    for(j = 0; j<lim; j += 2)
    {
        pos_1[m] = pos[m] - DIM[Index][j];
        m ++;
    }
    m = 0;
    for(j = 0; j<lim; j += 2)
        L[m++] = DIM[Index][j+1] - DIM[Index][j] + 1;
  
    if(k == 1 )
        address = pos_1[0];
  
    else if( k == 2)
        address = pos_1[0] * L[1] + pos_1[1];
  
    else
    {
      
        address = L[1] * pos_1[0] + pos_1[1];
        for(i = 2; i<k; i ++)
            address = address * L[i] + pos_1[i];
    }
  
  
    address = W[Index] * address + BA[Index];
  
    printf("%s[",NAME[Index]);
    for(i = 0; i<k; i ++)
    {
        printf("%d",pos[i]);
        if(i < k-1)
            printf(", ");
    }
    printf("] = %d\n",address);
    return 0;
}

481 - What Goes Up