10097 - The Color Game

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
samanpa
New poster
Posts: 1
Joined: Tue Jul 15, 2003 12:09 am

10097 - The Color Game

Post by samanpa » Tue Jul 15, 2003 12:13 am

Does any one have any test data for 10097

PingWeiWu
New poster
Posts: 1
Joined: Tue Oct 18, 2005 7:10 pm

Compile Error

Post by PingWeiWu » Tue Oct 18, 2005 7:16 pm

=====================
I just complie my code successful using gcc, but i got compile error throught online judge, can anybody help me with my problem ?
thanks in advanced !!
=====================
#include <stdio.h>
#include <stdlib.h>
#define true 1
#define false 0
const int unreachable = 10000;
int nCell;

struct myNode
{
struct myNode *link;
int x;
int y;
};
struct myQueue
{
struct myNode *front;
struct myNode *rear;
};
struct myNode* createNode(int i,int j)
{
struct myNode* theNode = (struct myNode*)malloc(sizeof(struct myNode));
theNode->link=NULL;
theNode->x=i;
theNode->y=j;
return theNode;
}
struct myQueue* createQueue()
{
struct myQueue *theQueue = (struct myQueue*)malloc(sizeof(struct myQueue));
theQueue->front = NULL;
theQueue->rear = NULL;
return theQueue;
}
int isEmpty(struct myQueue* theQueue)
{
if(theQueue->front==NULL)
return true;
else
return false;
}
void add2Queue(struct myQueue* theQueue,struct myNode* theNode)
{
if(isEmpty(theQueue))
{
theQueue->front = theNode;
theQueue->rear = theNode;
}
else
{
theQueue->rear->link = theNode;
theQueue->rear=theNode;
}
}
void delFromQueue(struct myQueue* theQueue)
{
if(isEmpty(theQueue))
{
printf("Queue is empty!! Deletion abort!!");
exit(0);
}
else
{
if(theQueue->front == theQueue->rear)
{
free(theQueue->front);
theQueue->front = NULL;
theQueue->rear = NULL;
}
else
{
struct myNode* tmp = theQueue->front->link;
free(theQueue->front);
theQueue->front = tmp;
}
}
}

void freeQueue(struct myQueue* theQueue)
{
while(theQueue->rear!=NULL)
{
struct myNode* tmp = (theQueue->rear)-1;
free(theQueue->rear);
theQueue->rear = tmp;
freeQueue(theQueue);
}
}
int convertIndex(int x,int y)
{
return nCell*(x-1)+(y-1);
}
main()
{
int runNum = 0;
int i,j;
int *pEdgeArray = 0;
int *pTraceArray = 0;
int minStep=unreachable;
int token1,token2,dest;

struct myQueue *theQueue = createQueue();

while(true)
{
scanf("%d",&nCell);
if(nCell<=0)
exit(0);

if((pEdgeArray = (int*)malloc(sizeof(int)*nCell*nCell)) == NULL)
{

}

if((pTraceArray = (int*)malloc(sizeof(int)*nCell*nCell)) == NULL)
{

}


for(i=1;i<=nCell;i++)
{
for(j=1;j<=nCell;j++)
{
scanf("%d",(pEdgeArray+convertIndex(i,j)));
}
}
scanf("%d%d%d",&token1,&token2,&dest);

for(i=1;i<=nCell; i++)
{
for(j=1;j<=nCell; j++)
{
if(i==dest||j ==dest)
{
*(pTraceArray+convertIndex(i,j)) = 0;

struct myNode* temp = createNode(i,j);
add2Queue(theQueue,temp);
}
else
*(pTraceArray+convertIndex(i,j)) = unreachable;
}
}

while(!isEmpty(theQueue))
{
int x,y;
x=theQueue->front->x;
y=theQueue->front->y;

delFromQueue(theQueue);

minStep = *(pTraceArray+convertIndex(x,y));
for(i = 1; i <= nCell; i++)
{
if(*(pEdgeArray+convertIndex(i,x)) == y)
{
if(*(pTraceArray+convertIndex(x,i)) > minStep+1)
{
*(pTraceArray+convertIndex(x,i)) = minStep+1;
*(pTraceArray+convertIndex(i,x)) = minStep+1;

struct myNode* node1 = createNode(x,i);
struct myNode* node2 = createNode(i,x);
add2Queue(theQueue,node1);
add2Queue(theQueue,node2);
}
}
}
}
++runNum;

printf("Game #%d\n",runNum);
if(*(pTraceArray+convertIndex(token1,token2))==unreachable)
printf("Destination is Not Reachable !\n\n");
else
printf("Minimun Number of Moves = %d\n\n",minStep);
}
}

User avatar
Cho
A great helper
Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong

Post by Cho » Tue Oct 18, 2005 8:04 pm

I got these errors when compile it in VC6.

Code: Select all

E:\uva\t.c(137) : error C2143: syntax error : missing ';' before 'type'
E:\uva\t.c(138) : error C2065: 'temp' : undeclared identifier
E:\uva\t.c(138) : warning C4047: 'function' : 'struct myNode *' differs in levels of indirection from 'int '
E:\uva\t.c(138) : warning C4024: 'add2Queue' : different types for formal and actual parameter 2
E:\uva\t.c(163) : error C2143: syntax error : missing ';' before 'type'
E:\uva\t.c(164) : error C2143: syntax error : missing ';' before 'type'
E:\uva\t.c(165) : error C2065: 'node1' : undeclared identifier
E:\uva\t.c(165) : warning C4047: 'function' : 'struct myNode *' differs in levels of indirection from 'int '
E:\uva\t.c(165) : warning C4024: 'add2Queue' : different types for formal and actual parameter 2
E:\uva\t.c(166) : error C2065: 'node2' : undeclared identifier
E:\uva\t.c(166) : warning C4047: 'function' : 'struct myNode *' differs in levels of indirection from 'int '
E:\uva\t.c(166) : warning C4024: 'add2Queue' : different types for formal and actual parameter 2

neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba

Post by neno_uci » Tue Oct 18, 2005 8:11 pm

Which problem are you trying to solve?, you also wrote 'Minumun' instead of 'Minumum', although this, of course, is not a reason for CE :D , best regards,

Yandry.

User avatar
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey » Tue Oct 18, 2005 9:16 pm

It's problem 10097.
In C you can't declare variables in the middle of a code block. You can submit your code as C++ and it will compile on the judge (but will give WA, not only for the reason neno_uci mentioned).

Another thing: If you publish your code on the board please use code tags.

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon » Sat Dec 30, 2006 6:19 pm

From what I can conclude, the minimum number of moves will never be greater than 20.

smgraham
New poster
Posts: 2
Joined: Mon Aug 26, 2013 8:34 pm

10097 - Wrong Answer

Post by smgraham » Mon Aug 26, 2013 9:02 pm

I don't know what quirky condition I am missing. My hand traces match my output, but every time... WA!

I've checked my output formatting 15 times.
I have not re-queued explored pairs. (avoid non-terminating searches)
I have not queued any dead ends (no pairs [n,0] or [0,n])
I have checked for a win condition on the 0th turn.

I am stumped!

smgraham
New poster
Posts: 2
Joined: Mon Aug 26, 2013 8:34 pm

Re: 10097 - Wrong Answer

Post by smgraham » Mon Aug 26, 2013 9:05 pm

Solved!
Missed the terminal "new line" after the last set. Should have checked the formatting 16 times!

LazyTym
New poster
Posts: 31
Joined: Tue Jun 24, 2014 9:10 pm

10097 - The Color Game!!!

Post by LazyTym » Thu Jul 10, 2014 7:58 pm

i cant understand this problem.pls anyone give explanation of input and output....... :(

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10097 - The Color Game!!!

Post by brianfry713 » Fri Jul 11, 2014 8:45 pm

Game 1
Tokens at 3 and 5. The token at 5 can't move, the token at 3 moves to 4.
Tokens at 4 and 5. The token at 5 can't move, the token at 4 moves to 5.
Tokens at 5 and 5. Both tokens are stuck at 5, 1 is unreachable.

Game 2
Tokens at 2 and 3. The token at 3 can't move, the token at 2 moves to 1.
Tokens at 1 and 3. Either token can move, if the token at 1 moves to 3, then:
Tokens at 3 and 5. Either token can move, if the token at 3 moves to 2, then:
Tokens at 2 and 5. Either token can move, if the token at 2 moves to 4, then:
Tokens at 4 and 5. Either token can move, if the token at 4 moves to 5, then:
Tokens at 5 and 5. Move a token to 6.
Check input and AC output for thousands of problems on uDebug!

LazyTym
New poster
Posts: 31
Joined: Tue Jun 24, 2014 9:10 pm

Re: 10097 - The Color Game!!!

Post by LazyTym » Sun Jul 13, 2014 6:15 pm

thanks bro.........brianfry713

Post Reply

Return to “Volume 100 (10000-10099)”