组合数学 UVa 11538 Chess Queen】的更多相关文章

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 bo…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2533 Root 11538 - Chess Queen Time limit: 2.000 seconds You probably know how the game of chess is played and how chess queen operates. Two chess qu…
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2533 三个方向, 横,竖,对角线~ #include<iostream> #include<cstdio> using namespace std; int main() { long long int n,m; while(scanf("%lld%l…
题目链接 题意:给出m行n列的棋盘,当两皇后在同行同列或同对角线上时可以互相攻击,问共有多少种攻击方式. 分析:首先可以利用加法原理分情况讨论:①两皇后在同一行:②两皇后在同一列:③两皇后在同一对角线( / 或 \ ): 其次利用乘法原理分别讨论: ①同一行时(A),先选某一行某一列放置其中一个皇后,共m*n种情况:其次在选出的这一行里的其他n-1个位置中选一个放另一个皇后:共m*n*(n-1)种情况: ②同一列时(B)情况相同,为n*m*(m-1)种情况: ③同一对角线(D)上时,先讨论 /…
考虑把皇后放在同一横排或者统一纵列,答案为nm(m-1)和nm(n-1),显然. 考虑同一对角线的情况不妨设,n<=m,对角线从左到右依次为1,2,3,...,n-1,n,n,n,...,n(m-n+1个n),n-1,n-2,...,2,1 还有另一个方向的对角线,所以算出来之后要乘二. 即答案为2(2*Σ(i to n-1) (i(i-1))    +   (m-n+1)n(n-1)) Σ(i to n-1) (i(i-1))怎么算呢? 可以拆成Σi² - Σi , i²的前缀和公式我就不推了…
题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种. 析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是行和列的,然后再算对角线,对角线是从2-min(m, n)的, 然后就能算出来. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <strin…
A Chess Queen 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 diagona…
Chess  Almost everyone knows the problem of putting eight queens on an  chessboard such that no Queen can take another Queen. Jan Timman (a famous Dutch chessplayer) wants to know the maximum number of chesspieces of one kind which can be put on an  …
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2533 题意:在n*m的棋盘上放两个(黑和白)相互攻击的皇后,求有多少种方法?  0<=(n,m)<=10e6; 下图是2*2的方案数12: 很明显要按行列还有对角三种来考虑,每种的方案数相加即可: 每一行我们要从m个格子中选择2个进行放所以方案数是m*(m-1),共有…
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2136 Problem A Another n-Queen Problem I guess the n-queen problem is known by every person who has studied backtracking. In this problem you s…