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的更多相关文章

  1. 【计数原理】【UVA11538】 Chess Queen

    传送门 Description 给你一个n*m的棋盘,在棋盘上放置一黑一白两个皇后,求两个皇后能够互相攻击的方案个数 Input 多组数据,每组数据包括: 一行,为n和m 输入结束标志为n=m=0. ...

  2. Uva 11538 - Chess Queen

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. 组合数学 UVa 11538 Chess Queen

    Problem A Chess Queen Input: Standard Input Output: Standard Output You probably know how the game o ...

  4. UVA11538 - Chess Queen(数学组合)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. UVA11538 Chess Queen

    题意 给一个\(n \times m\)的棋盘,输出有多少种方法放置两个互相攻击的皇后. \(n,m \leq 10^6\) 分析 参照刘汝佳的题解. 横.竖.斜三种情况互不相干,加法原理统计. 横竖 ...

  6. uva 11538 Chess Queen<计数>

    链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  7. 【基本计数方法---加法原理和乘法原理】UVa 11538 - Chess Queen

    题目链接 题意:给出m行n列的棋盘,当两皇后在同行同列或同对角线上时可以互相攻击,问共有多少种攻击方式. 分析:首先可以利用加法原理分情况讨论:①两皇后在同一行:②两皇后在同一列:③两皇后在同一对角线 ...

  8. 【组合计数】UVA - 11538 - Chess Queen

    考虑把皇后放在同一横排或者统一纵列,答案为nm(m-1)和nm(n-1),显然. 考虑同一对角线的情况不妨设,n<=m,对角线从左到右依次为1,2,3,...,n-1,n,n,n,...,n(m ...

  9. UVa 11538 Chess Queen (排列组合计数)

    题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种. 析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是 ...

随机推荐

  1. java实验报告&第三周学习总结

    实验报告: 实验1:求水仙花数在C语言中求水仙花数是一个复杂且长的代码,在java中可以通过简单的代码来实现操作,找出水仙花数: 图例如下: 试验2:求13+23-33+43-53.........9 ...

  2. 【零售App】—— react/ant design mobile项目爬坑

    一.H5制作 - 图片文本的动画效果 bug:打开一个模板,添加图片,添加动画效果,若先选定动画效果,再调节动画时间和延迟时间,则动画和延迟时间没有改变:若先调节动画时间和延迟时间在选定动画效果,则动 ...

  3. Spring boot 自定义一个starter pom

    用过springboot的自动配置会觉得非常方便,我们完全可以自己写一个starter pom,这样不仅可以有自动配置功能,而且具有更通用的的耦合度低的配置, 新建一个starter的maven项目, ...

  4. 五、python中MD5加密

    import hashlib '''用于加密相关的操作,代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法'''##### ...

  5. python - Tkinter 模块 - python 自带的gui模块

    Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口,位Python的内置模块,直接import tkinter即可使用. 1.创建窗口 from Tk ...

  6. 设计模式(5): vue 不监听绑定的变量

    概述 最近最近做项目的时候总会思考一些大的应用设计模式相关的问题,我把自己的思考记录下来,供以后开发时参考,相信对其他人也有用. 绑定变量 一般情况下,如果我们需要在组件中使用某个变量,会这么使用: ...

  7. hibernate 配置+注释

    Hibernate配置属性 属性名 用途 hibernate.dialect 一个Hibernate Dialect类名允许Hibernate针对特定的关系数据库生成优化的SQL. 取值 full.c ...

  8. CDS究竟是个什么鬼?它直接导致了次贷危机?

    周五,中国银行间市场交易商协会就确认了这一消息,信用违约互换(CDS)和信用联结票据(CLN)业务指引在今日正式发布实行. 当然,这则消息在中国普通投资者当中还没引起足够关注,但是在很多人看来CDS这 ...

  9. mybatisProxy

    config.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configurati ...

  10. 【Linux开发】【Qt开发】QT 同时支持鼠标和触摸屏

    QT 同时支持鼠标和触摸屏 现在 如果我要使用鼠标 导入环境变量 export QWS_MOUSE_PROTO=MouseMan:/dev/input/mice 使用触摸屏,导入环境变量 export ...