Friday, May 13, 2016

UVA 696 : How Many Knights -Solution

Unknown
#include<cstdio>
using namespace std;

int main()
{
     int m,n;
     while (scanf("%d%d",&m,&n)!=EOF)
         {
          if (m==0 && n==0) return 0;
          int ans,r,c;
          r=m;
          c=n;
          if (m>n)
          {
               int t=m;
               m=n;
               n=t;
          }
          if (m==1) ans=n;
          else if (m==2)
            ans =n/4*4+(n%4==1)*2+(n%4>1)*4;
          else ans =(m*n+1)/2;
          printf("%d knights may be placed on a %d row %d column board.\n",ans,r,c);
     }
    return 0;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,