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), 这是 ...
随机推荐
- List of Mozilla-Based Applications
List of Mozilla-Based Applications The following is a list of all known active applications that are ...
- CSS样式div
页面中,有很多样式标签:div标签,对标签定位的地方有: 1.<head>标签里加<style>标签,在<style>标签中添加样式.如: <style> ...
- C#学习基础
c#的值类型存储在栈里,而引用类型的引用存储在栈里,数据存储在堆里. c#new关键字为对象分配一个引用而非存储数据. 引用类型关键字ref: For example: Int y; void mym ...
- Selenium学习之==>三种等待方式
在UI自动化测试中,必然会遇到环境不稳定,网络慢的情况,这时如果你不做任何处理的话,代码会由于没有找到元素,而报错.这时我们就要用到wait(等待),而在Selenium中,我们可以用到一共三种等待, ...
- 12 oracle 数据库坏块--物理坏块-ORA-01578/ORA-01110
oracle 数据库坏块--物理坏块 数据坏块的类型物理坏块:通常是由于硬件损坏如磁盘异常导致.内存有问题.存储链有问题. IO有问题.文件系统有问题. Oracle本身的问题等逻辑坏块:可能都是软件 ...
- 【Spring】---【AOP】
转发几篇文章 专治不会看源码的毛病--spring源码解析AOP篇 Spring3:AOP 理解AOP 什么是AOP? 转自: http://www.cnblogs.com/xiexj/p/73668 ...
- ES6标准入门 第三章:变量的解构赋值
解构赋值:从数组和对象中提取值,对变量进行赋值. 本质上,这种写法属于“匹配模式”:只要等号两边的模式相同,左边的变量就会被赋予对应的值. 1.数组的结解构赋值 基本用法 let [foo, [[ba ...
- 转:【开源必备】常用git命令
原文:https://zhuanlan.zhihu.com/p/25868120 [开源必备]常用git命令 [已重置] 如今在技术领域,码农们习惯了开源,也离不开免费开源的代码,轻松获取代码,不 ...
- storm集群环境搭建
1.环境 Java环境 卸载虚机环境中自带的openJdk,安装sun的jdk,配置环境变量 2.安装storm 下载storm安装包 解压到安装目录,配置环境变量 vi /etc/profile # ...
- LAMP框架
一基本常识 LNMP (Linux + Nginx + MySQL + PHP) LAMP (Linux + Apache + MySQL + PHP) //php作为Apache的模块Apache. ...