UVa11538 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 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:
|
|
|||
|
Figure: in a (2x2) chessboard 2 queens can be in attacking position in 12 ways |
Given an (NxM) board you will have to decide in how many ways 2 queens can be in attacking position in that.
Input
Input file can contain up to 5000 lines of inputs. Each line contains two non-negative integers which denote the value of M and N (0< M, N£106) respectively.
Input is terminated by a line containing two zeroes. These two zeroes need not be processed.
Output
For each line of input produce one line of output. This line contains an integer which denotes in how many ways two queens can be in attacking position in an (MxN) board, where the values of M and N came from the input. All output values will fit in 64-bit signed integer.
Sample Input Output for Sample Input
|
2 2 100 223 2300 1000 0 0 |
12 10907100 11514134000 |
Problemsetter: Shahriar Manzoor
Special Thanks to: Mohammad Mahmudur Rahman
/*
分三种情况:
同行
同列
同斜
*/ #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll; const int M=; int get(){
char c;
int res=;
while(c=getchar(),!isdigit(c));
do{
res=(res<<)+(res<<)+(c-'');
}while(c=getchar(),isdigit(c));
return res;
} int main()
{
ll ans1,ans2,ans3,ans,n,m;
while(~scanf("%lld%lld",&n,&m))
{
if(n==&m==)break;
if(n>m)swap(n,m);
ans1=n*m*(m-);//同行
ans2=n*m*(n-);//同列
ans3=*n*(n-)*(*m-n-)/;//同斜
ans=ans1+ans2+ans3;
printf("%lld\n",ans);
}
return ;
}
UVa11538 A Chess Queen的更多相关文章
- 【计数原理】【UVA11538】 Chess Queen
传送门 Description 给你一个n*m的棋盘,在棋盘上放置一黑一白两个皇后,求两个皇后能够互相攻击的方案个数 Input 多组数据,每组数据包括: 一行,为n和m 输入结束标志为n=m=0. ...
- 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 ...
- UVA11538 - Chess Queen(数学组合)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA11538 Chess Queen
题意 给一个\(n \times m\)的棋盘,输出有多少种方法放置两个互相攻击的皇后. \(n,m \leq 10^6\) 分析 参照刘汝佳的题解. 横.竖.斜三种情况互不相干,加法原理统计. 横竖 ...
- 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列的棋盘,当两皇后在同行同列或同对角线上时可以互相攻击,问共有多少种攻击方式. 分析:首先可以利用加法原理分情况讨论:①两皇后在同一行:②两皇后在同一列:③两皇后在同一对角线 ...
- 【组合计数】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 (排列组合计数)
题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种. 析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是 ...
随机推荐
- Qt数据库之数据库连接池
前面的章节里,我们使用了下面的函数创建和取得数据库连接: void createConnectionByName(const QString &connectionName) { QSql ...
- IntelliJ IDEA2018破解教程
破解方法:下载破解补丁→修改配置文件→输入激活码→激活成功 由于JetBrains封杀,大部分激活服务器已经不能使用,使用下面的比较麻烦的方法也可以进行破解,但是有效期是到2100年(emmmm,也算 ...
- C/C++判断字符串是否包含某个字符串
C风格 #include <iostream> #include <string> #include <cstring> using namespace std; ...
- 学习Linux的基础网站
http://c.biancheng.net/view/726.html
- USB转换PS2接线原理
https://blog.csdn.net/dfyy88/article/details/4540170 USB转换PS2接线原理 2009年09月10日 18:36:00 阅读数:13285 USB ...
- 操作系统汇编语言之AT&T指令
转载时格式有问题,大家看原版吧! 作者:EwenWanW 来源:CSDN 原文:https://blog.csdn.net/xiaoxiaowenqiang/article/details/805 ...
- Lesson 2 Thirteen equals one
vicar 牧师 grocer 杂货铺店主 with a start 由于受到惊吓 Whtaever are you dong up here?你究竟在这上面干什么?whatever用于疑问句中,用以 ...
- (4.24)【mysql、sql server】分布式全局唯一ID生成方案
参考:分布式全局唯一ID生成方案:https://blog.csdn.net/linzhiqiang0316/article/details/80425437 分表生成唯一ID方案 sql serve ...
- springboot swagger教程😀
传送门开启:https://www.ibm.com/developerworks/cn/java/j-using-swagger-in-a-spring-boot-project/index.html
- CentOS8 下 Redis5.0.7 哨兵Sentinel 模式配置指南
下载Redis Redis下载链接 解压缩 tar -xzvf redis-5.0.7.tar.gz 编译安装 make和gcc依赖 可通过yum -y install gcc automake au ...