Tuesday, May 31, 2011

679 - Dropping Balls


Monday, May 30, 2011

10922 - 2 the 9s


10305 - Ordering Tasks


Friday, May 27, 2011

11110 - Equidivisions

#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>
#define M 103
using namespace std;

int Board[M][M],point[60];
int start[M][2],N,n;
char inp[10000];
int next[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

void format (int num);
void DFS_Visit(int,int);

int main()
{
    int i,j,f;
    //freopen("in.txt","r",stdin);

    while(gets(inp))
    {
        sscanf(inp,"%d",&n);
        if(!n)break;

        for(i=0;i<=n;i++)
            for(j=0;j<=n;j++)
                Board[i][j] = n;

        for(i=1;i<n;i++)
        {
            gets(inp);
            format(i);
        }

        f = 1;
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
            {
                if(!Board[i][j])
                    continue;
                N=1;

                DFS_Visit(i,j);
                if(N!=n){f=0;goto NEXT;}
            }
NEXT:
        if(f)
            printf("good\n");
        else
            printf("wrong\n");

        memset(Board,0,sizeof(Board));
        memset(point,0,sizeof(point));
        memset(start,0,sizeof(start));
    }
    return 0;
}

void DFS_Visit(int u,int v)
{
    int i,tu,tv,x;
    x = Board[u][v];
    Board[u][v] = 0;

    for(i=0;i<4;i++)
    {
        tu = u + next[i][0];
        tv = v + next[i][1];
        if(tu>=0&&tu<n&&tv>=0&&tv<n&&Board[tu][tv]==x)
        {
            N++;
            DFS_Visit(tu,tv);
        }
    }
}

void format (int num)
{
    char *pch;
    pch = strtok (inp, " ");

    while ( pch != NULL )
    {
        int c1 = atoi (pch);
        pch = strtok (NULL, " ");
        int c2 = atoi (pch);
        pch = strtok (NULL, " ");
        Board [c1 - 1] [c2 - 1] = num;
    }
}

11710 - Expensive subway


12015 - Google is Feeling Lucky


Tuesday, May 3, 2011

10994 - Simple Addition


10991 - Region


10970 - Big Chocolate


10916 - Factstone Benchmark


10879 - Code Refactoring


10878 - Decode the tape


10812 - Beat the Spread!


10790 - How Many Points of Intersection?


10783 - Odd Sum


10696 - f91


10591 - Happy Number


10589 - Area


10579 - Fibonacci Numbers


10499 - The Land of Justice


10494 - If We Were a Child Again


10469 - To Carry or not to Carry


10451 - Ancient Village Sports


10432 - Polygon Inside A Circle


10394 - Twin Primes


10375 - Choose and divide


10370 - Above Average


10347 - Medians


10346 - Peter's Smokes


10340 - All in All