## 10024 - Curling up the cube

Moderator: Board moderators

henar2
New poster
Posts: 30
Joined: Mon Nov 26, 2001 2:00 am

### 10024 - Curling up the cube

Hi, I can't find why this code doesn't go on.

[c]
#include<stdio.h>

int sum_col(int map[6][6],int col);
int sum_row(int map[6][6],int row);
void rotate(int map[6][6]);

main()
{
int map[6][6];
int i,j,row,col,cases,k,temp;
scanf("%d",&cases);
for(i=0;i<cases;i++)
{
for(j=0;j<6;j++)
{
for(k=0;k<6;k++)
scanf("%d",&map[j][k]);
}
row=-1;
for(k=0;k<3;k++)
{
for(j=0;j<6;j++)
{
temp=sum_row(map,j);
if(temp==4)
{
row=j;
break;
}
}
if(row==-1)
rotate(map);
else
break;
}

if(row==-1)
{
printf("incorrect\n");
goto finished;
}
col=-1;
for(j=0;j<6;j++)
{
temp=sum_col(map,j);
if(temp==3)
{
col=j;
break;
}
}
if(col==-1)
{
printf("incorrect\n");
goto finished;
}
if(row-1>=0 && row+1<6 && col-1>=0 && col+1<6 && col+2<6)
{
if(map[row][col]==1 && map[row][col-1]==1
&& map[row][col+1]==1 && map[row][col+2]==1
&& map[row-1][col]==1 && map[row+1][col]==1)
{
printf("correct\n");
goto finished;
}
}
if(row-1>=0 && row+1<6 && col-1>=0 && col-2>=0 && col+1<6)
{
if(map[row][col]==1 && map[row][col-1]==1
&& map[row][col+1]==1 && map[row][col-2]==1
&& map[row-1][col]==1 && map[row+1][col]==1)
{
printf("correct\n");
goto finished;
}
}
printf("incorrect\n");
finished:
if(i!=cases-1)
printf("\n");
}
}

int sum_row(int map[6][6],int row)
{
int i,sum;
sum=0;
for(i=0;i<6;i++)
sum+=map[row];
return(sum);
}

int sum_col(int map[6][6],int col)
{
int i,sum;
sum=0;
for(i=0;i<6;i++)
sum+=map[col];
return(sum);
}

void rotate(int map[6][6])
{
char map2[6][6];
int i,j;
for(i=0;i<6;i++)
for(j=0;j<6;j++)
map2[j]=map[j];
for(i=0;i<6;i++)
for(j=0;j<6;j++)
map[j][5-i]=map2[j];
return;
}
[/c]

wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am
mind to briefly explain your algorithm in words? i'm not used to understand other's code (neither my own code )

but i guess what you miss maybe this case

XX
.XX
..XX

this can be curled up into a cube. (right?)

henar2
New poster
Posts: 30
Joined: Mon Nov 26, 2001 2:00 am
What i do in my messy code is:
1--> Look for a row that sum 4. If not, then rotate and look for again. If after 3 rotations there isn't a row with sum=4 then: incorrect.
2--> Look for a column that sum 3 in the last rotate image. If it doesn't exist then: incorrect.
3--> In this point I have the row and the column where the figure intersect, then I check if the figure:

00X0
XXXX
00X0

or

0X00
XXXX
0X00

(where X=1)

is in the image because i have the intersect point.

and that's all, i think it must go on but i am getting wrong answer.

And, about your comment, I think that your case can't be curled up into a cube, at least, as i have understood the problem statement.

wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am

OOXO
XXXX
XOOO

also can, do you think so?

henar2
New poster
Posts: 30
Joined: Mon Nov 26, 2001 2:00 am
Sorry, you are correct.
I understood that I should find a shape like:

00X0
XXXX
00X0

And that is not true. So, I'll rewrite my code.
Thanks a lot.

yan4546
New poster
Posts: 7
Joined: Fri Nov 15, 2002 4:17 am
Contact:

### 10024

I have tried lots of inputs and I found no mistakes.
but I always get the WA;
I don't know why.
Can you help me?

Following are some of my inputs and outputs:

--------------------------------------------------------
Group 1:

intput:
0 0 0 0 0 0
0 0 1 1 0 1
0 0 0 1 1 1
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

output:
incorrect

Group 2:

input:
0 0 0 0 0 0
0 0 0 1 1 0
0 0 1 1 0 0
0 1 1 0 0 0
0 0 0 0 0 0

output:
correct

:win

Can you send some of your datas to me?

Thank you!
aaaaaaaaaaaaaaaaaaaaa

Astrakan
New poster
Posts: 24
Joined: Sun Nov 03, 2002 12:18 pm
Location: Sweden
The output for your test cases is correct. However, did you notice that this is a multiple input-problem (blue check mark)? Your program should accept input like this:

Code: Select all

``````2

0 0 0 0 0 0
0 0 1 1 0 1
0 0 0 1 1 1
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 0 1 1 0
0 0 1 1 0 0
0 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
``````
and produce output like this:
incorrect

correct
(see http://acm.uva.es/problemset/minput.html)

alex[LSD]
Learning poster
Posts: 53
Joined: Sat Jan 24, 2004 9:22 pm
Location: Tomsk, Siberia, RUSSIA
Contact:

### One more question...

Code: Select all

``````......
.***..
......
....*.
....*.
....*.
``````

is SUCH a case possible in this problem?
The more contests are held, the happier I am.

MUBBASHER
New poster
Posts: 10
Joined: Mon Oct 04, 2004 5:23 am

### 10024 NEED TEST DATA

I a m getting wrong answer from acm-site.

if some body know about getting sample inputs and ouputs from acm site for problem 10024. or from some othwer resourse please tell it to me.

Or if somebody already solved the problem please post me the smples produced by his program. i have already posted my code in last Topic please test it also.

MUBBASHER
New poster
Posts: 10
Joined: Mon Oct 04, 2004 5:23 am

### 10024

I m getting problem in solving 10024 "Curling up he cube"

perhaps i m not getting the correct way to solve th problem.

Here are steps througjh which i tried to solve my problem.

First i have made a class of 'FACE' with four
pointers "left,Right,Top ,Bottom".

Then i have linked face of inputed 'ones'. in another face link list.

then recursivly checked it's validation with the standrad cube.

I have checked my code for almost all problems. It gives answer
correct.

BUT ACM Judge Says Wrong answer
WHY

guayoyo
New poster
Posts: 11
Joined: Wed Aug 17, 2005 5:59 pm
Location: Caracas, Venezuela

### Easier than you think...

Hi MUBBASHER. I'm new to this board, and I can see your post have no replies, so I would explain you all my failed solutions...

First, I tried the way you have posted (in 3 different ways) and all were WAs... that it because when you curl the cube to one side, maybe the top of a face changes, and that is difficult to catch...

The other way i tried, was to create the 12 answers in the program and search the pattern (moved, rotated, etc...), and WA...

Until I solved problem 10409 - Die Game, which consist of rotate a six-faced dice and answer the face that was on the top... the solution for this problem was not to use pointers to mark adjacent faces, was to write four routines, moveNorth(), moveSouth(), moveWest() and moveEast() to rotate the dice in that direction (i.e.: moveNorth() makes the top face now is the north face, the north face is the bottom face, the bottom face is the south face and the south face is the top face).

What makes the solution easier is the fact that when you move the dice, you rotate the contents of the faces of the dice, so the top is always the top, and so on.

Once you solve this problem, you can use the code to rotate the dice to rotate the cube over the paper, and if after rotating the cube the six faces have been on the bottom with a 1 on the paper, then is "correct", else if "incorrect",...

(I came to this solution 8 months after my first WA solution)...
10024 - Guayoyo has Curled Up the Cube!

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
I liked your idea, guayoyo, so I implemented my solution that way.

Here's some I/O (weird, will comment bellow):

Code: Select all

``````7

0 0 0 0 0 0
0 0 0 1 0 0
0 0 0 1 0 0
0 0 1 1 1 0
0 0 0 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 0 1 1 0
0 0 1 1 0 0
0 0 0 1 1 0
0 0 0 0 0 0
0 0 0 0 0 0

0 0 0 1 0 0
0 0 0 1 0 0
0 0 0 1 0 0
0 0 0 1 0 0
0 0 0 1 0 0
0 0 0 1 0 0

0 0 0 1 0 0
0 0 0 1 0 0
0 0 1 1 0 0
0 0 0 1 1 0
0 0 0 0 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 0 1 0 0 0
0 0 1 0 1 0
0 0 0 0 1 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 0 1 0 0 0
0 0 1 1 1 0
0 0 0 0 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 0 1 1 0 0
0 0 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0

``````

Code: Select all

``````correct

incorrect

incorrect

correct

incorrect

incorrect

correct``````
Note that the last case is not a cube, but my AC program reports it as such. I submitted it to check it for time (thought I did some silly stuff) and it got accepted. Unless I misunderstood the problem, which makes it even worse, heh.

Darko

New poster
Posts: 35
Joined: Wed May 02, 2007 11:48 pm
Location: Brasil

Hi,
this input is possible?

Code: Select all

``````......
.***..
......
....*.
....*.
....*.
``````

tgoulart
New poster
Posts: 42
Joined: Sat Oct 21, 2006 8:37 am
Location: Alegrete, Brazil

this input is possible?

Code: Select all

``````......
.***..
......
....*.
....*.
....*.
``````