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

Uva 11538 Chess Queen (数学规律题)

2013-05-14 13:58 381 查看
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:

//11538 Chess Queen Accepted    C++ 0.024   2013-04-22 08:15:00
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
unsigned long long n, m;
while(cin >> n >> m)  {
if(!m&&!n) break;
if(n>m) swap(n, m);
long long res = n*m*(m+n-2)+2*n*(n-1)*(3*m-n-1)/3 ;
cout << res << endl;
}
return 0;
}


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