Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

where is the fault

Posted by huangkun at 2006-11-20 16:39:27 on Problem 2734
#include<stdio.h>
#include<string.h>
int b[1000][1000];
int qsx[100],qsy[100];
main()
{
int m,n,i;
long int s,time=1;
int q,qs,qx,qy;
while(scanf("%d%d",&m,&n),!(m==0||n==0))
{
   s=0;
   memset(b, 0, sizeof(b));
/*Read Queens*/
   scanf("%d",&q);
	qs=q;
   for(i=0;i<q;++i)
   {
      scanf("%d%d",&qx,&qy);
      qsx[i]=qx-1;
      qsy[i]=qy-1;
      b[qx-1][qy-1]=2;
   }
/*Read and count Knight*/
    scanf("%d",&q);
    for(;q>0;--q)
    {
       scanf("%d%d",&qx,&qy);
	qx-=1;
	qy-=1;
       b[qx][qy]=2;
       if(qx-1>=0&&qy-2>=0)  b[qx-1][qy-2]=1;
       if(qx-1>=0&&qy+3<=n)  b[qx-1][qy+2]=1;
       if(qx-2>=0&&qy-1>0)  b[qx-2][qy-1]=1;
       if(qx-2>=0&&qy+1<n)  b[qx-2][qy+1]=1;
       if(qx+1<m&&qy-2>=0)  b[qx+1][qy-2]=1;
       if(qx+1<m&&qy+2<n)  b[qx+1][qy+2]=1;
       if(qx+2<m&&qy-1>=0)  b[qx+2][qy-1]=1;
       if(qx+2<m&&qy+1<n)  b[qx+2][qy+1]=1;
    }
/*Pawns*/

    scanf("%d",&q);
    for(;q>0;--q)
    {
       scanf("%d%d",&qx,&qy);
	qx-=1;
	qy-=1;
       b[qx][qy]=2;
    }
/*queens*/
for(i=0;i<qs;++i)
{
      for(qx=qsx[i]-1,qy=qsy[i];qx>=0&&b[qx][qy]!=2;--qx)
	b[qx][qy]=1;
      for(qx=qsx[i],qy=qsy[i]-1;qy>=0&&b[qx][qy]!=2;--qy)
	b[qx][qy]=1;
      for(qx=qsx[i]+1,qy=qsy[i];qx<m&&b[qx][qy]!=2;++qx)
	b[qx][qy]=1;
      for(qx=qsx[i],qy=qsy[i]+1;qy<n&&b[qx][qy]!=2;++qy)
	b[qx][qy]=1;
      for(qx=qsx[i]-1,qy=qsy[i]-1;qx>=0&&qy>=0&&b[qx][qy]!=2;--qx,--qy)
	b[qx][qy]=1;
      for(qx=qsx[i]+1,qy=qsy[i]-1;qx<m&&qy>=0&&b[qx][qy]!=2;++qx,--qy)
	b[qx][qy]=1;
      for(qx=qsx[i]-1,qy=qsy[i]+1;qx>=0&&qy<n&&b[qx][qy]!=2;--qx,++qy)
	b[qx][qy]=1;
      for(qx=qsx[i]+1,qy=qsy[i]+1;qx<m&&qy<n&&b[qx][qy]!=2;++qx,++qy)
	b[qx][qy]=1;
}
/*count*/
    for(i=0,s=0;i<m;++i)
      for(q=0;q<n;++q)
	 if(b[i][q]==0)
	   ++s;
    printf("Board %ld has %ld safe squares.\n",time,s);
    ++time;
}
return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator