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

kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

Re: 750 - 8 Queens Chess Problem

Post by kbr_iut »

u should look at the sample output carefully,,,,,
ur code is okay,,,I just changed this portion of ur code

Code: Select all

 printf("%d      ",pos1++);
to

Code: Select all

 printf("%2d      ",pos1++);
and this portion

Code: Select all

printf("#      1 2 3 4 5 6 7 8\n\n");
to

Code: Select all

printf(" #      1 2 3 4 5 6 7 8\n\n");
and got AC.....hope it helps.after getting AC immediately remove ur code.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................
stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Re: 750 - 8 Queens Chess Problem

Post by stcheung »

Just got AC and here are some tips:
(1) DO NOT print a blank line after the last test case. In other words, only print a blank after each test case except for the last one. Otherwise you will get WA
(2) Only print the leading space before the solution number if it's less than 10. Otherwise you will get PE.
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: help!p:-750

Post by lnr »

There is related volume for this.
invadrFlip
New poster
Posts: 8
Joined: Fri Aug 10, 2012 7:48 am

why WA???

Post by invadrFlip »

All my outputs have been correct for all test cases. The problem is probably with the printing (ugh.. :roll: )

//removed because updated code has been posted
Last edited by invadrFlip on Fri Sep 14, 2012 11:59 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 750 - 8 Queens Chess Problem

Post by brianfry713 »

Don't print a space at the end of a line.
Check input and AC output for thousands of problems on uDebug!
invadrFlip
New poster
Posts: 8
Joined: Fri Aug 10, 2012 7:48 am

Re: 750 - 8 Queens Chess Problem

Post by invadrFlip »

nice catch, but still nada..... :(
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 750 - 8 Queens Chess Problem

Post by brianfry713 »

Does nada/nothing mean you're still getting WA? If you need help, then post your updated code that doesn't print a space at the end of a line.
Check input and AC output for thousands of problems on uDebug!
invadrFlip
New poster
Posts: 8
Joined: Fri Aug 10, 2012 7:48 am

Re: 750 - 8 Queens Chess Problem

Post by invadrFlip »

Yeah sorry. I dunno what the problem could be.... No spaces at end of lines. Only empty lines between cases. No line at end case.

// code reposted in a later post.
Last edited by invadrFlip on Thu Sep 20, 2012 6:36 am, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 750 - 8 Queens Chess Problem

Post by brianfry713 »

Post your code surrounded by the code tags, otherwise extra tabs and spaces are removed and for this problem it makes the output wrong.
Use class Main.
http://uva.onlinejudge.org/index.php?op ... &Itemid=30
Check input and AC output for thousands of problems on uDebug!
invadrFlip
New poster
Posts: 8
Joined: Fri Aug 10, 2012 7:48 am

Re: 750 - 8 Queens Chess Problem

Post by invadrFlip »

Again... I dunno what the problem could be.... No spaces at end of lines. Only empty lines between cases. No line at end case.

/* code removed because it was solved */
Last edited by invadrFlip on Sun Oct 14, 2012 11:53 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 750 - 8 Queens Chess Problem

Post by brianfry713 »

Print a newline at the end of the output.
Check input and AC output for thousands of problems on uDebug!
invadrFlip
New poster
Posts: 8
Joined: Fri Aug 10, 2012 7:48 am

Re: 750 - 8 Queens Chess Problem

Post by invadrFlip »

Thank you, bro! sorry it took me so long to respond, but that was it. Thanks.
udoy
New poster
Posts: 7
Joined: Sat Sep 28, 2013 11:27 am

750 - 8 Queens Chess Problem

Post by udoy »

any one kindly help me.........getting frequent wa's :evil:

Code: Select all

#include<stdio.h>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#define max 3000
#define pb(x) push_back(x)
#define valid(i,j,x,y) (i>=0 && i<x &&j<y && j>=0 )

using namespace std;
int no=1,x,y;
const int N = 8;
int position[N],arr[92][18];
int sum,mmax,ara[20][20],kk;
// Check if a position is safe
bool isSafe(int queen_number, int row_position)
{

    // Check each queen before this one
    // cout<<" "<<queen_number<<endl;
    for(int i=0; i<queen_number; i++)
    {

        // Get another queen's row_position
        int other_row_pos = position[i];

        // Now check if they're in the same row or diagonals
        if(other_row_pos == row_position || // Same row
                other_row_pos == row_position - (queen_number-i) || // Same diagonal
                other_row_pos == row_position + (queen_number-i))   // Same diagonal
            return false;
    }
    return true;
}


// Recursively generate a tuple like [0 0 0 0], then [0 0 0 1] then etc...
void solve(int k)
{
    if(k == N) // We placed N-1 queens (0 included), problem solved!
    {
        // Solution found!
        //    cout << "Solution: "<<no++<<"  ";
        sum=0;
      //  cout<<"comb  "<<kk<<" ;";
        for(int i=0; i<N; i++)
        {
                   arr[kk][i]=position[i];
                  //  cout<<position[i]+1<<" ";

        }
        kk++;

         // cout << endl;
    }
    else
    {
        for(int i=0; i<N; i++) // Generate ALL combinations
        {
            // Before putting a queen (the k-th queen) into a row, test it for safeness
            if(isSafe(k,i))
            {
                position[k] = i;
                // Place another queen
                solve(k+1);
            }
        }
    }
}

int main()
{
    #ifndef ONLINE JUDGE
    freopen("input.txt","r",stdin);
    #endif // ONLINE
    int kase,flag=0;
    solve(0);
    scanf("%d",&kase);
    for (; kase-- ; )
    {




        int sum=1;
        mmax=0;
if(flag)
    cout<<endl;

        flag=1;
        (scanf("%d %d",&x,&y));
        printf("SOLN       COLUMN\n");
        printf(" #      1 2 3 4 5 6 7 8\n\n");



        {
            for (int i=0;i<kk ; i++)
            {
                if(arr[i][x-1]==y-1)
                {
                 // printf("%2d      ",pos1++);
                    printf("%2d     ",sum++);
                    for (int j=0;j<8 ;j++ )
                    cout<<" "<<arr[i][j]+1;

                cout<<endl;
                }
            }
                ;
        }
       // if(kase)
        //    cout<<endl;
            ;

    }
    return 0;
}

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

Re: 750 - 8 Queens Chess Problem

Post by brianfry713 »

It looks like you figured it out.
Check input and AC output for thousands of problems on uDebug!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 750 - 8 Queens Chess Problem

Post by brianfry713 »

That is AC code
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 7 (700-799)”