Page 5 of 6

Re: 750 - 8 Queens Chess Problem

Posted: Wed Jul 09, 2008 10:59 am
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.

Re: 750 - 8 Queens Chess Problem

Posted: Sun Sep 07, 2008 4:31 am
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.

Re: help!p:-750

Posted: Mon Oct 06, 2008 6:44 pm
by lnr
There is related volume for this.

why WA???

Posted: Mon Sep 10, 2012 2:23 am
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

Re: 750 - 8 Queens Chess Problem

Posted: Mon Sep 10, 2012 10:04 pm
by brianfry713
Don't print a space at the end of a line.

Re: 750 - 8 Queens Chess Problem

Posted: Tue Sep 11, 2012 6:33 am
by invadrFlip
nice catch, but still nada..... :(

Re: 750 - 8 Queens Chess Problem

Posted: Tue Sep 11, 2012 8:36 pm
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.

Re: 750 - 8 Queens Chess Problem

Posted: Fri Sep 14, 2012 11:58 pm
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.

Re: 750 - 8 Queens Chess Problem

Posted: Wed Sep 19, 2012 12:42 am
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

Re: 750 - 8 Queens Chess Problem

Posted: Thu Sep 20, 2012 6:36 am
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 */

Re: 750 - 8 Queens Chess Problem

Posted: Thu Sep 20, 2012 9:26 pm
by brianfry713
Print a newline at the end of the output.

Re: 750 - 8 Queens Chess Problem

Posted: Sun Oct 14, 2012 11:53 pm
by invadrFlip
Thank you, bro! sorry it took me so long to respond, but that was it. Thanks.

750 - 8 Queens Chess Problem

Posted: Wed Nov 13, 2013 3:40 am
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;
}


Re: 750 - 8 Queens Chess Problem

Posted: Wed Nov 13, 2013 11:02 pm
by brianfry713
It looks like you figured it out.

Re: 750 - 8 Queens Chess Problem

Posted: Tue Dec 03, 2013 2:29 am
by brianfry713
That is AC code