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), 这是 ...
随机推荐
- Tomcat部署时war和war exploded区别以及平时踩得坑
war和war exploded的区别 在使用IDEA开发项目的时候,部署Tomcat的时候通常会出现下边的情况: 是选择war还是war exploded 这里首先看一下他们两个的区别: war模式 ...
- PTA编程总结三
7-1 抓老鼠啊~亏了还是赚了? (20 分) 某地老鼠成灾,现悬赏抓老鼠,每抓到一只奖励10元,于是开始跟老鼠斗智斗勇:每天在墙角可选择以下三个操作:放置一个带有一块奶酪的捕鼠夹(T),或者放置一块 ...
- 腾讯这套SpringMVC面试题你懂多少(面试题和答案)
1.什么是 SpringMvc? 答:SpringMvc 是 spring 的一个模块,基于 MVC 的一个框架,无需中间整合层来整 2.Spring MVC 的优点: 答:1)它是基于组件技术的.全 ...
- lr参数与C语言函数参数的区别
C变量不能再lr函数中使用: c变量必须定义在lr函数之前: LR参数可以在LR函数中直接当做字符串使用. LR参数是lr自己封装的一个钟对象, LR参数的表达方式:{ParamName}
- Mybaits配置多个数据库操作sql环境
mybitas可以配置sql语句适用于不同数据库下的操作,因为不同数据库sql语句可能有差别,接下来介绍如果进行操作 1.在jdbc.properprites配置驱动 jdbc.driver=com. ...
- leetcode 239. 滑动窗口最大值(python)
1. 题目描述 给定一个数组 nums,有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧.你只可以看到在滑动窗口内的 k 个数字.滑动窗口每次只向右移动一位. 返回滑动窗口中的最大值. 示 ...
- JDK1.7安装配置环境变量+图文说明Jmeter安装
Jmeter通常用于并发测试,本文介绍Jmeter工具的安装步骤. 工具/原料 WIN7 Jmeter安装包 JDK 一.安装JDK 1 [步骤一]安装jdk 1.下载jdk,到官网下载jdk ...
- 在word中的表格指定位置插入一行
//创建一个Document类对象,并加载Word文档 Document doc = new Document(); doc.LoadFromFile(@"C:\Users\Administ ...
- 用 Python 解答两道来自阿里伯乐系统的笔试题
目录 目录 前言 题目一 分析 实现 题目二 分析 实现 前言 朋友到阿里面试,分享两道小题,博主比较闲就试着用 Python 解答一下,实现方式肯定是多种多样的,优劣也会各有不同,欢迎交流. 题目一 ...
- Linux_KVM虚拟机
目录 目录 Hpyervisor的种类 安装KVM 使用virsh指令管理虚拟机 KVM虚拟机的网络设置 Hpyervisor的种类 hpyervisor:是一种VMM(Virtual Machine ...