Page 1 of 2
Posted: Fri Jan 04, 2002 5:39 pm
by FlyDeath
I don't know what exactly the solution is , but this is what I thought:
n,m are integers
Rook:the smaller of n,m
Knight: n*m/2
Queen: the smaller of n,m
King: (n/2)*(m*2)
ACM 278
Posted: Wed Jul 03, 2002 6:22 am
by htl
I don't know why this code can't get accepted. It always gets WA. But I think the algorithm isn't wrong.Could someone find out the bug?
[c]
#include<stdio.h>
void main(void)
{
int i,x,m,n;
char chess;
scanf("%d",&i);
for(x=0;x<i;x++)
{
fflush(stdin);
scanf("%c %d %d",&chess,&m,&n);
if(chess=='r')
{
if(m>=n)
printf("%d\n",n);
else
printf("%d\n",m);
}
if(chess=='k')
{
if(m*n%2==1)
printf("%d\n",(m*n+1)/2);
else
printf("%d\n",m*n/2);
}
if(chess=='Q')
{
if(m>=n)
printf("%d\n",n);
else
printf("%d\n",m);
}
if(chess=='K')
{
if(m%2==1)
m=(m+1)/2;
else
m/=2;
if(n%2==1)
n=(n+1)/2;
else
n/=2;
printf("%d\n",m*n);
}
}
}
[/c]
Posted: Wed Jul 03, 2002 10:12 am
by Picard
put a space in scanf's formating before reading %c, or else it will read white spaces too.
btw:
if (a%2==1) b=(a+1)/2; else b=a/2
has the same result as only:
b=(a+1)/2
Posted: Wed Jul 03, 2002 12:06 pm
by htl
I finally got accepted, thanks.
278 - Chess
Posted: Tue Dec 02, 2003 6:45 am
by Shantanu
Can anyone give me some critical input. I am trying this quite a some time. I am getting WA.
Thanks in advanced
Posted: Tue Dec 02, 2003 7:05 am
by sohel
For rook and queen it is the minimum of ( row, column).
For knight - picture the board as a grid consisting of black and white colours and count the number of black or white squares.
For king - do the same thing as knight but skip the alternate row.
Hope it helps.

Posted: Thu Dec 04, 2003 8:06 pm
by Shantanu
I used this algorithm. But still WA. I think the Knigths causing me the problem. Can anyone help me with some input.
Thanks for the reply
Posted: Sat Dec 06, 2003 7:32 am
by sohel
HI Shantanu,
Here is some input that might come to a help;
k 5 5
k 4 4
k 5 4
k 4 5
output:
13
8
10
10
Hope it helps.

Posted: Wed Aug 04, 2004 7:23 am
by Minilek
sohel wrote:
For rook and queen it is the minimum of ( row, column).
I don't understand..say the board is 2 by 2. Then how can you possibly put 2 queens on the board so that they don't attack each other? Should the answer here not be 1?
[Edit] I am foolish..I didn't realize the problem constraints say that m and n are both greater than or equal to 4[/Edit]
278-CE
Posted: Sat Jul 01, 2006 1:37 pm
by serendipity
#include<stdio.h>
#include<conio.h>
int find_min(int p,int q)
{
if(p>q)
return q;
else
return p;
}
int main(void)
{
long cs;
int m, n;
char chpcs;
scanf("%ld", &cs);
while(cs)
{
chpcs=getch();
scanf("%d %d",&m,&n);
if(chpcs=='r'||chpcs=='Q')
printf("%d\n", find_min(m,n));
else if(chpcs=='k')
printf("%d\n",m*n/2);
else
printf("%d\n",( ((m+1)/2) * ((n+1)/2) ) );
cs--;
}
return 0;
}
Posted: Mon Dec 04, 2006 5:18 pm
by Debashis Maitra
just solve this problem without using conio.h and getch().
I think you will be able to get AC after this
And remove your code after AC
Posted: Thu Mar 22, 2007 2:33 pm
by Uttam Dwivedi
the minimum possible size of the board is 4*4...
Posted: Thu Aug 16, 2007 2:03 am
by jbernadas
I used differents formulas for the King and the Knight.
Re: 278 Chess
Posted: Sun Apr 05, 2009 8:30 pm
by tasnif
the following code is giving wrong answer what is the problem?
#include<iostream>
using namespace std;
int main(void)
{
int testno,testcase=1,product,m,n;
char a;
cin>>testno;
while(testcase<=testno)
{
cin>>a>>m>>n;
product=1;
if(a=='r'||a=='q')
{
if(m<=n)cout<<m<<'\n';
else cout<<n<<'\n';
}
else if(a=='k')
{
if((m*n)%2==0)cout<<(m*n)/2<<'\n';
else cout<<(m*n)/2+1<<'\n';
}
else if(a=='K')
{
if((m%2)==0 )product*=(m/2);
else product*=(m/2)+1;
if((n%2)==0)product*=(n/2);
else product*=(n/2)+1;
cout<<product<<'\n';
}
testcase++;
}
return 0;
}
Re: 278 Chess
Posted: Fri Oct 22, 2010 12:33 pm
by Shafaet_du
This will certainly help you:
Code: Select all
24
K 8 10
K 7 9
K 7 7
K 8 8
K 6 10
K 5 10
Q 8 10
Q 7 9
Q 7 7
Q 8 8
Q 6 10
Q 5 10
k 8 10
k 7 9
k 7 7
k 8 8
k 6 10
k 5 10
r 8 10
r 7 9
r 7 7
r 8 8
r 6 10
r 5 10
output:
Code: Select all
20
20
16
16
15
15
8
7
7
8
6
5
40
32
25
32
30
25
8
7
7
8
6
5
happy programming!!