## 10855 - Rotated squares

Moderator: Board moderators

### 10855 - Rotated squares

Hi all,
I'm getting WA for this easy problem. Please give me some I/O. By the way i'm giving the code to rotate the small square. Is it ok ???? Thankx in advance.

Code: Select all
void rotate_grid()
{
int i,j;
int sro1r,sro1c,sro2r,sro2c,sro3r,sro3c;
int rot1r,rot1c,rot2r,rot2c,rot3r,rot3c,rot4r,rot4c;

sro1r=0;      // 90 degree
sro1c=n-1;

sro2r=n-1;      // 180 degree
sro2c=0;

sro3r=0;      // 270 degree
sro3c=-(n-1);

// Given Second Square is already at rot[0][]][]
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
rot1r=i;   // 0 degree
rot1c=j;
rot2r=i+sro1r+j;   // 90 degree
rot2c=j+sro1c-j;

rot3r=rot2r+sro2r-j;   // 180 degree
rot3c=rot2c+sro2c-j;

rot4r=rot3r+sro3r-j;   // 270 degree
rot4c=rot3c+sro3c+j;

rot[1][rot2r][rot2c]=rot[0][rot1r][rot1c];
rot[2][rot3r][rot3c]=rot[0][rot1r][rot1c];
rot[3][rot4r][rot4c]=rot[0][rot1r][rot1c];
}
sro1r--;
sro1c--;

sro2r--;
sro2c++;

sro3r++;
sro3c++;
}
/*for(i=0;i<n;i++)
{
for(j=0;j<4;j++)
pf(" %s",rot[j][i]);
puts("");
}
puts("");*/

}
Chok
New poster

Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

Hi Chok

I have found a mistake in your code
just add this line after calling the rotated_grid() function.
Code: Select all
for (i = 0; i < n; i++)
rot[1][i][n] = NULL, rot[2][i][n] = NULL, rot[3][i][n]= NULL;

Thanks
MAP

mohiul alam prince
Experienced poster

Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

Hi Prince,
Thanks for ur help. But i'm still not get ACC. I think my checking is not ok. Here is my full code. Please verify it. Thanks in advance.

Code: Select all
Cut after Acc...
Last edited by Chok on Wed Jul 27, 2005 5:21 pm, edited 1 time in total.
Chok
New poster

Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

Hi

just increase ur max value and get your AC.

Thanks
MAP

mohiul alam prince
Experienced poster

Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

Hi Prince,
Thank you very much. Got ACC. I missed those think. Again thanx. Bye and Good luck.
Chok
New poster

Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

I changed my solution to one that only computes hash values, and it turns out that I can get AC in 0.006s
sclo
Guru

Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm

Interesting, what's your hash function? I wonder how it works.....

There's no upper bound on N or n correct? I tried brute force and got AC with 9.2 sec by luck. I guess that means N can be big?
yiuyuho
A great helper

Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States

### n<=100

N<=100
Pregunt
New poster

Posts: 7
Joined: Thu Jun 16, 2005 8:17 am
Location: M