UVA 11538 Chess queen////title:////in the n * m of the chessboard, put two queens, a black, a white//to allow two queens to attack each other's release method, how many kinds of////problem-solving ideas:////Queen attack way only in the same row, the same column, or the same diagonal//on, category discussion:////1): The same line, then the white method has n * m species, the black method has m-1 species////2): The same column, then the white methods have m * N species, black and n-1 species////3): The same diagonal, then the first Queen's method along the diagonal is//1 , 2,3....n-1,n,...., n,n-1,..., 3,2,1, because the diagonal//altogether m+n-1 bar, each side has n-1, then put n m-n+1 species, then//diagonal method for//sigma (i * (i-1)) {1<=i<= n-1} * (m-n+1) *n* (n-1)//Because there are two diagonal lines, the main diagonal and the diagonal. Here should be *2//again with unsigned long long on the ~~~~////sentiment:////Algorithm Contest Training Guide on the topic, It's amazing. ~~~//fighting#include <cstdio> #include <iostream> #include <cstring> #include < Algorithm>using namespace Std;typedef unsigned long long ull;int main () {ull n,m;//freopen ("1.txt", "R", stdin); while ( CIN >> n >> m) {if (!n &&!m) break;if (n > M) swap (n,m); ull x;x = n * (n-1) * (2 * n-1)/6;x = X -N * (n-1)/2;x = x * 2;x = x + (m-n + 1) * n * (n-1); x = x * 2;x = x + M * n * (M + n-2); cout << x <& Lt Endl;}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA 11538 Chess Queen