您的位置:首页 > 产品设计 > UI/UE

UVa 11538 - Chess Queen

2014-02-23 16:04 441 查看
Problem A
Chess Queen
Input: Standard Input

Output: Standard Output

You probably know how the game of chess is played and how chess queen operates. Two chess queens are in attacking position when they are on same row, column or diagonal of a chess board. Suppose two such chess queens (one black and the other white) are placed on (2x2) chess board. They can be in attacking positions in 12 ways, these are shown in the picture below:

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

int main()
{
long long int n,m,n1,sum;
//freopen("aa.txt","r",stdin);
while(scanf("%lld%lld",&n,&m)!=EOF)
{
sum=n1=0;
if(n==0&&m==0)
break;
sum+=m*n*(n-1+m-1);
if(n>m)
swap(n,m);
n1+=((n-1)*n*(2*n-1)/6-n*(n-1)/2)*4;
n1+=(m-n+1)*n*(n-1)*2;
sum+=n1;
printf("%lld\n",sum);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: