750 - 8 Queens Chess Problem

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

Moderator: Board moderators

l314
New poster
Posts: 7
Joined: Sun Jan 28, 2007 9:53 am

Post by l314 »

I have checked out the post that you give me and I try to fixe my code, but I still got P.E.

Below is one of my output case.
I can't find the difference from the simple output of problem 750.
plz help me find out this bug, thank you.

Code: Select all

code has been killed
Last edited by l314 on Tue Jan 30, 2007 5:58 pm, edited 1 time in total.
helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo »

Your program prints some extra blank lines at the begining..
iamthewall
New poster
Posts: 3
Joined: Thu Apr 05, 2007 12:41 am

750 P.E

Post by iamthewall »

Hi everyone i got P.E on the 8 Queens problem. I sent it a lot of times and i made a lot of modifications. I read al the suggestions of this forum but i didnt figure out the problem. ANy help plz

Thanks
Last edited by iamthewall on Thu Apr 19, 2007 10:22 pm, edited 1 time in total.
iamthewall
New poster
Posts: 3
Joined: Thu Apr 05, 2007 12:41 am

HELP

Post by iamthewall »

Well at least somebody can help me with a sample input and the output?
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Try the cases...

Input:

Code: Select all

2

1 7

8 3
Output:

Code: Select all

SOLN       COLUMN
 #      1 2 3 4 5 6 7 8

 1      2 7 3 6 8 5 1 4
 2      3 7 2 8 6 4 1 5
 3      4 2 7 3 6 8 1 5
 4      4 7 3 8 2 5 1 6
 5      5 2 4 6 8 3 1 7
 6      6 3 7 2 4 8 1 5
 7      6 3 7 2 8 5 1 4
 8      6 4 2 8 5 7 1 3

SOLN       COLUMN
 #      1 2 3 4 5 6 7 8

 1      1 5 8 6 3 7 2 4
 2      1 6 8 3 7 4 2 5
 3      2 6 8 3 1 4 7 5
 4      3 5 8 4 1 7 2 6
 5      3 6 8 1 4 7 5 2
 6      3 6 8 1 5 7 2 4
 7      3 6 8 2 4 1 7 5
 8      4 2 8 5 7 1 3 6
 9      4 2 8 6 1 3 5 7
10      4 6 8 2 7 1 3 5
11      4 6 8 3 1 7 5 2
12      5 1 8 4 2 7 3 6
13      5 1 8 6 3 7 2 4
14      5 2 8 1 4 7 3 6
15      5 3 8 4 7 1 6 2
16      7 3 8 2 5 1 6 4
Hope these help.
Ami ekhono shopno dekhi...
HomePage
ExUCI
New poster
Posts: 14
Joined: Sat Aug 12, 2006 3:31 am
Location: USA

Post by ExUCI »

Dude your algorithm is fine, but you made a lot mistakes printing the output, here is the list:

- An extra space at the end of every line except the second one.
- Change \t for spaces
- The empty line is between datasets, not at the end of every dataset

That's all, remove your code after AC
iamthewall
New poster
Posts: 3
Joined: Thu Apr 05, 2007 12:41 am

Post by iamthewall »

Thx .. finally i did it
soddy
New poster
Posts: 23
Joined: Tue May 29, 2007 1:39 am

Post by soddy »

PE means u did not output in the format as u shld hv been....there is no mistake in ur code.....chk out the other threads for dis issue
nymo
Experienced poster
Posts: 149
Joined: Sun Jun 01, 2003 8:58 am
Location: :)

Thanks Jan...

Post by nymo »

Your sample IO helps... the problem was with the sequence number of the solution... I did terrible things and modifications... but didn't understand the correct format... output format is a little hazy.
regards,
nymo
Iffat
New poster
Posts: 25
Joined: Sat Jul 22, 2006 9:47 am

Post by Iffat »

Code: Select all

CUT 
I got WA for this code...:(I test all test cases and they r ok with my code..... pls help..
thanx in advance :)
Last edited by Iffat on Thu Nov 22, 2007 7:19 am, edited 1 time in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

There should be a blank line between cases. Your code cant handle that perfectly. Check your output carefully by saving the output in a file. Hope that helps.
Ami ekhono shopno dekhi...
HomePage
Iffat
New poster
Posts: 25
Joined: Sat Jul 22, 2006 9:47 am

Post by Iffat »

AC :)
thanx jan....it really helps nd i have also edited the array size...
Saul Hidalgo
New poster
Posts: 18
Joined: Wed Jan 03, 2007 2:36 am
Location: Los Teques, Venezuela

Post by Saul Hidalgo »

Thanks for the input. I got AC. :wink:
mukit
New poster
Posts: 48
Joined: Wed Nov 21, 2007 10:09 am
Location: Dhaka , Bangladesh
Contact:

PE : 750 - 8 Queens Chess Problem

Post by mukit »

Hi , I'm getting PE. I read all post before and all tried all ways.
Please help.

Code: Select all

#include<iostream>
#include<iomanip>
using namespace std;
int fres,hash,chess[11][11],input[11][11]={0},colset[11],l_diag[20],r_diag[20];
int res[11],row,col;
void backTrack(int r)
{
	int c,m,n,tmax;
	if(r==9)
	{
		for(int i=1;i<=8;i++)
		{
			if(i==col && res[i]==row)
			{
				hash++;
				cout<<" "<<hash<<"     ";
				for(int j=1;j<=8;j++)
				{
					cout<<" "<<res[j];
				}
				cout<<endl;
				break;
			}
		}
		if(fres<tmax)
		{
			fres=tmax;
		}
		return;
	}
	for(c=1;c<=8;c++)
	{
		if(chess[r][c]==0 && colset[c]==0 && l_diag[r+c]==0 && r_diag[r-c+8]==0)
		{
			chess[r][c]=1;
			colset[c]=1;
			l_diag[r+c]=1;
			r_diag[r-c+8]=1;
			res[r]=c;
			backTrack(r+1);
			chess[r][c]=0;
			colset[c]=0;
			l_diag[r+c]=0;
			r_diag[r-c+8]=0;
		}
	}
	return;
}
int main()
{
	int a;
	while(cin>>a)
	{
		fres=0;
		for(int x=1;x<=a;x++)
		{
			cin>>row>>col;
			for(int i=0;i<10;i++)
			{
				for(int j=0;j<10;j++)
				{
					chess[i][j]=0;
				}
				colset[i]=0;
			}
			for(int i=0;i<=20;i++)
			{
				l_diag[i]=0;
				r_diag[i]=0;
			}
			cout<<"SOLN       COLUMN"<<endl;
			cout<<" #      1 2 3 4 5 6 7 8"<<endl<<endl;
			hash=0;
			backTrack(1);
			if(x!=a)
			{
				cout<<endl;
			}
		}
	}
	return 0;
}
n_arun89
New poster
Posts: 2
Joined: Wed Dec 12, 2007 12:28 am
Location: India

Re: 750 - 8 Queens Chess Problem

Post by n_arun89 »

thanks
removed after AC :D
Last edited by n_arun89 on Mon Jul 14, 2008 5:57 pm, edited 1 time in total.
Programming is Fun
Post Reply

Return to “Volume 7 (700-799)”