255 - Correct Move

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

Moderator: Board moderators

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

255 - Correct Move

Post by htl »

Why does the code get WA? Just position checking...
[c]
#include<stdio.h>
void main(void)
{
int k,q,m,kx,ky,mx,my,qx,qy;
while(scanf("%d %d %d",&k,&q,&m)!=EOF)
{
if(k==q)
{
printf("Illegal state\n");
continue;
}
if(q%8!=m%8 && q/8!=m/8 || m==k || m==q)
{
printf("Illegal move\n");
continue;
}
kx=k/8,ky=k%8,mx=m/8,my=m%8,qx=q/8,qy=q%8;
if(kx==qx && qx==mx)
if(my>ky && my<8 && qy>ky && qy<8 || my<ky && my>0 && qy<ky && qy>0)
;
else
{
printf("Illegal move\n");
continue;
}
if(ky==qy && qy==my)
if(mx>kx && mx<8 && qx>kx && qx<8 || mx<kx && mx>0 && qx<kx && qx>0)
;
else
{
printf("Illegal move\n");
continue;
}
if(mx==kx && (ky>0 && my==ky-1 || ky<7 && my==ky+1))
{
printf("Move not allowed\n");
continue;
}
if(my==ky && (kx>0 && mx==kx-1 || kx<7 && mx==kx+1))
{
printf("Move not allowed\n");
continue;
}
if(m==49 && k==56 || m==9 && k==0 || m==14 && k==7 || m==54 && k==63)
printf("Stop\n");
else
printf("Continue\n");
}
}
[/c]
Calvin
New poster
Posts: 5
Joined: Sat Mar 08, 2003 12:50 pm

Need input for 255 - Correct Move

Post by Calvin »

Hi everybody!

i got every time wrong answer for the 255 ! Could anyone give me some big input in order to try to discover a bug in my source code ??

Thanks a lot,

Calvin
bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:

Post by bery olivier »

Hi calvin, my little padawan !

Here is my input/output
19 32 49
0 35 41
20 38 36
20 59 3
61 56 40
33 21 9
24 7 3
34 23 13
3 55 52
43 17 5
13 4 26
48 45 46
24 19 46
20 22 4
13 62 25
35 9 24
43 13 57
3 26 19
58 16 53
13 22 57
18 48 38
1 32 51
20 15 36
42 20 61
42 46 18
51 7 32
2 2 5
29 21 48
45 12 51
4 6 47
53 44 61
22 32 17
38 6 18
59 5 39
42 24 19
49 56 61
52 62 50
11 48 52
23 37 19
30 21 1
11 20 6
44 38 59
51 56 19
56 32 58
17 52 54
11 50 34
11 38 21
59 27 10
33 46 21
55 48 44
13 54 12
51 51 23
45 8 5
14 3 57
4 57 51
54 28 6
29 50 17
57 60 29
41 18 25
26 0 59
18 12 51
7 36 1
15 42 52
18 36 34
13 25 49
42 31 53
29 49 45
26 15 12
45 40 6
46 36 48
58 25 11
32 27 30
11 17 37
48 51 52
10 38 7
41 29 20
27 12 0
43 24 29
20 31 56
57 16 38
20 28 21
47 58 17
1 32 49
53 21 61
29 29 47
59 50 57
8 50 36
33 17 1
1 10 44
18 49 2
46 7 60
42 25 17
11 12 1
33 10 3
0 58 56
50 52 22
38 26 18
55 28 27
3 9 60
52 12 62
60 9 17
22 27 1
35 28 43
46 31 55
41 25 25
30 47 26
57 3 13
22 30 52
32 27 45
45 26 48
54 44 38
18 45 36
47 26 58
16 18 31
41 44 14
26 7 55
30 21 23
60 11 17
25 56 40
52 42 10
33 18 55
16 54 47
42 50 3
61 18 51
42 32 4
50 24 46
9 48 10
20 2 40
14 43 38
56 54 0
12 47 52
3 32 23
53 35 39
9 24 19
41 29 17
3 12 60
51 23 48
54 0 57
35 38 14
26 39 28
10 28 22
42 51 34
15 28 38
39 47 29
5 2 38
18 62 16
42 47 20
42 41 8
18 56 0
57 22 35
23 45 61
11 17 9
40 55 52
24 21 5
26 59 45
26 13 51
11 33 6
53 42 48
46 42 28
6 15 47
51 14 42
6 24 2
62 13 14
20 19 54
17 1 16
31 52 42
2 59 6
44 45 17
24 11 7
40 58 54
54 37 61
15 40 49
29 54 56
49 46 55
50 62 13
40 42 30
36 49 62
18 3 1
29 11 46
25 3 8
0 1 48
40 51 40
32 44 56
15 36 23
15 49 9
58 17 59
44 16 36
47 18 10
59 1 28
62 9 58
0 58 21
51 35 21
33 28 62
6 52 31
56 61 47
11 57 0
28 31 58
46 41 39
48 7 24
58 3 21
53 24 20
26 45 21
55 44 9
44 13 43
42 61 49
37 61 43
5 56 55
47 33 20
55 58 4
58 16 52
19 36 48
2 58 39
47 4 2
61 48 57
59 34 39
57 15 19
51 7 56
22 28 62
17 32 46
33 22 39
7 8 34
2 47 54
7 49 56
55 44 41
27 20 39
43 39 36
50 33 30
16 32 19
49 16 41
9 55 58
17 27 29
1 18 36
51 12 38
32 53 46
53 30 38
30 3 3
0 34 46
33 53 33
50 32 50
43 28 36
7 57 45
26 30 62
38 6 1
29 53 52
59 28 22
0 31 12
34 14 43
25 48 44
58 35 15
23 9 2
17 55 46
48 55 53
54 56 16
45 46 55
10 5 21
42 18 18
57 61 18
42 43 53
15 58 16
25 61 11
17 44 34
9 34 52
2 51 37
49 44 29
54 2 11
9 20 21
8 39 1
51 30 58
47 47 38
45 58 54
26 30 16
61 19 33
50 56 43
31 23 46
33 34 32
54 56 24
31 57 33
62 53 42
46 28 31
42 20 15
9 36 61
29 7 24
22 51 23
45 34 10
17 4 42
10 28 13
5 62 5
58 41 36
24 10 36
44 25 19
18 24 61
26 49 8
14 9 37
49 20 60
53 62 43
18 13 60
17 18 7
59 55 12
6 28 8
32 48 32
56 46 14
42 55 32
52 29 58
9 26 10
9 7 59
22 4 49
41 12 5
33 25 23
61 33 19
46 3 26
30 17 59
22 49 53
52 45 33
16 55 22
23 52 32
27 38 42
39 44 2
1 4 43
35 24 13
38 51 12
55 47 59
42 38 26
25 8 49
17 31 38
6 0 54
45 43 15
26 45 42
31 25 19
55 39 21
44 51 56
28 47 32
3 11 25
12 60 5
43 36 30
44 28 48
24 43 55
6 23 37
32 42 1
8 1 33
60 58 26
44 27 7
56 53 36
54 58 40
27 25 52
56 10 32
37 2 13
60 40 38
40 42 44
41 12 14
37 38 22
1 45 20
54 19 1
50 59 58
12 48 49
23 17 13
26 31 7
3 6 44
45 51 42
58 2 20
33 25 61
16 45 36
35 47 37
31 42 29
17 28 16
35 42 29
3 49 53
10 31 16
61 10 20
1 30 3
26 29 61
9 2 32
56 40 48
35 7 21
1 24 53
43 54 8
30 44 43
61 60 47
9 17 57
40 20 56
6 19 57
9 51 21
50 37 30
57 59 24
19 49 60
10 57 61
54 38 41
52 22 8
6 16 7
27 10 16
47 4 56
35 26 0
10 57 10
6 18 60
55 15 55
50 13 11
25 55 21
48 1 13
1 9 2
12 25 8
16 19 36
43 20 20
37 30 56
56 27 3
8 19 9
22 31 2
15 52 53
16 2 15
25 4 1
51 13 2
8 50 14
28 8 31
58 1 12
23 5 49
43 14 43
11 16 51
1 7 11
4 22 26
9 24 43
22 26 6
10 41 58
18 10 3
20 23 32
25 10 27
39 53 51
56 42 31
0 53 42
23 17 43
47 61 47
11 4 57
53 0 17
1 3 27
24 36 46
34 1 3
25 52 29
4 20 5
57 0 62
12 43 0
10 28 24
14 23 9
14 40 20
18 4 11
55 50 13
56 54 37
45 20 9
2 26 34
2 26 39
46 27 34
12 51 46
35 60 56
12 18 8
17 29 23
5 42 42
60 17 34
18 27 27
44 62 10
8 38 13
35 9 16
23 56 0
21 50 12
39 58 48
5 19 61
48 62 16
3 33 21
30 61 19
30 8 37
6 21 19
16 37 27
9 37 62
59 50 23
55 36 44
12 34 20
11 51 26
44 9 12
43 28 15
51 3 46
10 22 13
48 49 19
23 49 36
10 10 45
47 54 42
19 12 34
7 39 47
17 51 58
46 3 39
49 50 19
8 0 8
58 20 19
44 56 4
55 39 27
47 18 38
59 53 23
36 37 42
24 32 49
28 9 4
15 29 50
16 38 37
37 57 45
31 61 41
7 26 23
26 1 15
Illegal move
Illegal move
Continue
Continue
Continue
Illegal move
Continue
Illegal move
Continue
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal state
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal state
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Continue
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal state
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Continue
Illegal move
Continue
Continue
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Continue
Continue
Illegal move
Continue
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Continue
Continue
Continue
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Continue
Continue
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal state
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Move not allowed
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Continue
Continue
Illegal move
Illegal move
Move not allowed
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Move not allowed
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal state
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Illegal move
Continue
Illegal move
Illegal move
Illegal move
Illegal move
Not AC yet Image AC at last Image
MD.Morsalin-Al-Saadi
New poster
Posts: 7
Joined: Wed Dec 17, 2003 2:53 pm
Location: Dhaka
Contact:

Post by MD.Morsalin-Al-Saadi »

Hi bery olivier,
I have checked all your inputs but i am still getting WA. What can be the reason. Please help!
rajsekar_manokaran
New poster
Posts: 9
Joined: Fri Feb 20, 2004 6:48 am
Location: India
Contact:

Got it AC

Post by rajsekar_manokaran »

I also checked all the inputs that eh had given. My program also was giving proper answer but gave WA when submitted.

Then i found that the mistake was:

when seeing the kings's move, i incremented king's pos without seeing if it wraps to the next row.

May be that is the mistake in yours.
Check it up
vivander
New poster
Posts: 8
Joined: Sat May 21, 2005 2:13 am

255 - WA

Post by vivander »

This is my code for this problem. Why I have WA?

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int main (int car, char** v) {

	int  i,j,num1,num2, posicion, N1_X, N1_Y, N2_X, N2_Y, POS_X, POS_Y;
	char linea[100];
		
	while(fgets(linea,100,stdin)!=NULL){

		sscanf(linea,"%d %d %d",&num1,&num2,&posicion);

		N1_X= num1%8;
		N2_X= num2%8;
		POS_X= posicion%8;
		N1_Y= num1/8;
		N2_Y= num2/8;
		POS_Y= posicion/8;
		
		
		if (num1==num2) printf("Illegal state\n");
		else if ((num1==posicion)||(num2==posicion)) printf("Illegal move\n");
		else if ((N2_X!=POS_X)&&(N2_Y!=POS_Y)) printf("Illegal move\n");			
		else if ((N2_X==POS_X)&&(abs(N1_X-POS_X)>1)) printf("Continue\n");
		else if ((N2_Y==POS_Y)&&(abs(N1_Y-POS_Y)>1)) printf("Continue\n");
		else if ((N2_X==POS_X)&&(abs(N1_X-POS_X)==1)&&(POS_Y!=N1_Y)) printf("Continue\n");
		else if ((N2_X==POS_X)&&(abs(N1_X-POS_X)==1)&&(POS_Y==N1_Y)) printf("Move not allowed\n");			
		else if ((N2_Y==POS_Y)&&(abs(N1_Y-POS_Y)==1)&&(POS_X!=N1_X)) printf("Continue\n");
		else if ((N2_Y==POS_Y)&&(abs(N1_Y-POS_Y)==1)&&(POS_X==N1_X)) printf("Move not allowed\n");			
		else if (((N2_X==POS_X)||(N2_Y==POS_Y))&&((N2_X!=N1_X)&&(N2_Y!=N1_Y)&&(POS_X!=N1_X)&&(POS_Y!=N1_Y))) printf("Continue\n");			
		else if ((N1_X==POS_X)&&(N2_X==POS_X)&&(((N1_Y-1>POS_Y)&&(POS_Y>N2_Y))||((N1_Y+1<POS_Y)&&(POS_Y<N2_Y))||
				((N1_Y<N2_Y)&&(N2_Y<POS_Y))||((N1_Y>N2_Y)&&(N2_Y>POS_Y)))) printf("Continue\n");
		else if ((N1_X==POS_X)&&(N2_X==POS_X)&&(((N1_Y>POS_Y)&&(POS_Y>N2_Y)&&(N1_Y-1==POS_Y))||((N1_Y<POS_Y)&&(POS_Y<N2_Y)&&(N1_Y+1==POS_Y)))) printf("Move not allowed\n");
		else if ((N1_Y==POS_Y)&&(N2_Y==POS_Y)&&(((N1_X-1>POS_X)&&(POS_X>N2_X))||((N1_X+1<POS_X)&&(POS_X<N2_X))||
				((N1_X<N2_X)&&(N2_X<POS_X))||((N1_X>N2_X)&&(N2_X>POS_X)))) printf("Continue\n");
		else if ((N1_Y==POS_Y)&&(N2_Y==POS_Y)&&(((N1_X>POS_X)&&(POS_X>N2_X)&&(N1_X-1==POS_X))||((N1_X<POS_X)&&(POS_X<N2_X)&&(N1_X+1==POS_X)))) printf("Move not allowed\n");		
		else if ((((num1==0)&&(posicion==9))||((num1==7)&&(posicion==14))||((num1==56)&&(posicion==49))||
				((num1==63)&&(posicion==54)))&&((N2_X==POS_X)||(N2_Y==POS_Y))) printf("Stop\n");
		else printf("Illegal move\n");
		
	}
	
	return 1;	
}
shu
New poster
Posts: 6
Joined: Sat Jul 16, 2005 1:43 pm
Contact:

Post by shu »

Your code failed when there's any input like : 0 1 9
It should output 'Stop' instead of 'Continue'.

Tips :
Do checking step by step, ie. first check for 'Illegal state', then 'Illegal move', 'Move not allowed', 'Stop', and finally 'Continue' if the input pass all the checking. This way your code will get clearer and easier to avoid/locate the bug :D
best regards,
shu
Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:

Post by Jemerson »

I'm also facing the same problem of you guys, but couldn't understand how you solved your mistake. Could you please explain it better?
UFCG Brazil - Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!
Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:

Post by Jemerson »

Solved my problem, in fact the problem is in determining if the king is stucked or not and the above test cases don't test it correctly.
Don't know where in my algorithm things were wrong, but I solved it in such an easy way. All you must do is notice that the king can only get stucked up if its in the corner and the queen is diagonally in front of it.

Good Luck
UFCG Brazil - Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!
barrima
New poster
Posts: 2
Joined: Mon Feb 18, 2013 9:45 pm

255 - Need input ..

Post by barrima »

In this Problem
255 - Correct move
Can any one provide any input file or any corner test cases?
I checked all the test cases on this topic
http://online-judge.uva.es/board/viewto ... f=2&t=4157
but I did passed them

here's my code, if someone's interested :

Code: Select all

   AC
Last edited by barrima on Wed Feb 20, 2013 9:31 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 255 - Need input ..

Post by brianfry713 »

Input:

Code: Select all

48 46 47
AC output:

Code: Select all

Continue
Check input and AC output for thousands of problems on uDebug!
barrima
New poster
Posts: 2
Joined: Mon Feb 18, 2013 9:45 pm

Re: 255 - Need input ..

Post by barrima »

That was really useful :)
Tyvm ^^
inoryy
New poster
Posts: 1
Joined: Mon May 19, 2014 7:07 pm

Re: Need input for 255 - Correct Move

Post by inoryy »

Corner cases:

Code: Select all

0 14 9
7 9 14
56 54 49
63 49 54

Code: Select all

Stop
Stop
Stop
Stop
axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

255 - Correct Move

Post by axelblaze »

I have checked all the input bery given... my code gives the correct answar but still I'm getting WA..
here's my code:

Code: Select all

removed after ac
by the way, thanks to bery for his inputs... :wink: :wink:
Last edited by axelblaze on Fri Aug 08, 2014 2:48 am, edited 1 time in total.
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: Need input for 255 - Correct Move

Post by lighted »

Try this

Code: Select all

9 8 14
34 33 35
37 36 38
Output

Code: Select all

Illegal move
Illegal move
Illegal move
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Post Reply

Return to “Volume 2 (200-299)”