UVa 11538 Chess Queen (排列组合计数)
题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种。
析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是行和列的,然后再算对角线,对角线是从2-min(m, n)的,
然后就能算出来。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e2 + 100;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline int gcd(int a, int b){ return b ? gcd(b, a%b) : a; }
inline int lcm(int a, int b){ return a * b / gcd(a, b); }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int main(){
LL n, m;
while(cin >> m >> n && m+n){
if(m > n) swap(m, n);
cout << (m*n*n+m*m*n) - m*n*2 + ((m*(m-1)*(2*m-1))/6-1-(m+1)*(m-2)/2)*4 + m*(m-1)*(n-m+1)*2 << endl;
}
return 0;
}
UVa 11538 Chess Queen (排列组合计数)的更多相关文章
- Uva 11538 - Chess Queen
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 组合数学 UVa 11538 Chess Queen
Problem A Chess Queen Input: Standard Input Output: Standard Output You probably know how the game o ...
- 【组合计数】UVA - 11538 - Chess Queen
考虑把皇后放在同一横排或者统一纵列,答案为nm(m-1)和nm(n-1),显然. 考虑同一对角线的情况不妨设,n<=m,对角线从左到右依次为1,2,3,...,n-1,n,n,n,...,n(m ...
- uva 11538 Chess Queen<计数>
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...
- 【基本计数方法---加法原理和乘法原理】UVa 11538 - Chess Queen
题目链接 题意:给出m行n列的棋盘,当两皇后在同行同列或同对角线上时可以互相攻击,问共有多少种攻击方式. 分析:首先可以利用加法原理分情况讨论:①两皇后在同一行:②两皇后在同一列:③两皇后在同一对角线 ...
- hdu 6114 chess(排列组合)
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- UVA 12906 Maximum Score 排列组合
Maximum Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vie ...
- POJ 2249-Binomial Showdown(排列组合计数)
Binomial Showdown Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18457 Accepted: 563 ...
- 【BZOJ1008】越狱(排列组合计数,容斥原理)
题意: 思路: #include<cstdio> #include<cstdlib> #include<iostream> #include<algorith ...
随机推荐
- [NOIP1999] 普及组
回文数 /*By SilverN*/ #include<algorithm> #include<iostream> #include<cstring> #inclu ...
- P2863 [USACO06JAN]牛的舞会The Cow Prom
洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom 题目描述 The N (2 <= N <= 10,000) cows are so excited: it's ...
- codeforces 873F(后缀数组)
题意 给一个长度不超过200000的字符串s,假定有一个字符串a,这个字符串在s中出现次数是f(a),你需要让$|a|f(a)$最大. 但是有一些位置是禁止的,即以该位置为结束位置的字符串不计数. 分 ...
- sublime text 3注册码
—– BEGIN LICENSE —– Michael Barnes Single User License EA7E-821385 8A353C41 872A0D5C DF9B2950 AFF6F6 ...
- maven打包时的三方包的选择顺序
在一个项目有多个模块引用多个版本的某个插件(或者叫三方包.jar包等)时,如何解决版本冲突问题?最终选用某个版本还是选择几个版本? maven在遇到上面的情况时,会智能处理版本冲突,最终选择一个版本, ...
- CheckStyle: 解决Unicode导致LineLength出错的问题
在checkstyle.xml中,加上如下代码: <?xml version="1.0" encoding="UTF-8"?> <module ...
- 【转】JavaScript错误处理和堆栈追踪
原文: https://www.cnblogs.com/caoru/p/6699583.html --------------------------------------------------- ...
- 最新---java多线程下载文件
import java.io.InputStream; import java.io.RandomAccessFile; import java.net.HttpURLConnection; impo ...
- MongoDB使用入门
1.MongoDB的安装 步骤一:下载MongoDB 下载安装包:http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.4.tgz 步骤二:设置 ...
- Effective JavaScript Item 39 绝不要重用父类型中的属性名
本系列作为Effective JavaScript的读书笔记. 假设须要向Item 38中的Actor对象加入一个ID信息: function Actor(scene, x, y) { this.sc ...