UVA11538 Chess Queen
题意
给一个\(n \times m\)的棋盘,输出有多少种方法放置两个互相攻击的皇后。
\(n,m \leq 10^6\)
分析
参照刘汝佳的题解。
横、竖、斜三种情况互不相干,加法原理统计。
横竖都好计算,斜着需要推一推。
然后注意溢出问题。
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
{
data=data*10+ch-'0';
ch=getchar();
}
return data*w;
}
template<class T>T read(T&x)
{
return x=read<T>();
}
using namespace std;
typedef unsigned long long ull;
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ull n,m;
while(read(n)|read(m))
{
if(n>m)
swap(n,m);
printf("%llu\n",n*m*(m+n-2)+2*n*(n-1)*(3*m-n-1)/3);
}
return 0;
}
UVA11538 Chess Queen的更多相关文章
- UVA11538 - Chess Queen(数学组合)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- Uva 11538 - Chess Queen
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa11538 A Chess Queen
A Chess Queen Problem A Chess Queen Input: Standard Input Output: Standard Output You probably know ...
- 组合数学 UVa 11538 Chess Queen
Problem A Chess Queen Input: Standard Input Output: Standard Output You probably know how the game o ...
- 【计数原理】【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&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), 这是 ...
随机推荐
- 初识HTML和CSS
HTML 1.一套规则,浏览器认识的规则. 2.开发者: 学习Html规则 开发后台程序: - 写Html文件(充当模板的作用) ****** - 数据库获取数据,然后替换到html文件的指定位置(W ...
- hadoop2.6.0集群配置
1.修改机器名 集群的搭建最少需要三个节点,机器名分别修改为master,slave1,slave2.其中以master为主要操作系统. 修改hostname: sudo gedit /etc/hos ...
- String C++完整实现。
String C++实现 改进: /* 版权信息:狼 文件名称:String.h 文件标识: 摘 要:对于上版本简易的String进行优化跟进. 改进 1.(将小块内存问题与大块分别对待)小内存块每个 ...
- IOS-源代码管理工具(Git)
一.简介 什么是git? git是一款开源的分布式版本控制工具 在世界上所有的分布式版本控制工具中,git是最快.最简单.最流行的 git的起源 作者是Linux之父:Linus Benedict ...
- Mysql加载配置默认路径
查看命令 mysqld --verbose --help|grep "Default options" -n1 输出结果 11-12:Default options are rea ...
- LeetCode OJ:Jump Game II(跳跃游戏2)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- LeetCode OJ:H-Index(H指数)
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- APUE学习笔记——5缓冲Buffering、流、文件对象
缓冲的几个基本概念 缓冲的作用:减少系统read和write的次数. 全缓冲 系统标准I/O缓冲区被写满时才进行真正的I/O操作. 磁盘文件一般使用全缓冲 ...
- win2008 服务器文件夹权限配置
通过控制文件夹权限来提高站点的安全性. 这一篇权限设置包括二个方面,一个是系统目录.盘符的权限,一个是应用程序的上传文件夹权限设置. 系统目录 确保所有盘符都是NTFS格式,如果不是,可以用命令 co ...
- IIS:连接数、并发连接数、最大并发工作线程数、应用程序池的队列长度、应用程序池的最大工作进程数详解
Internet Information Services(IIS,互联网信息服务),是由微软公司提供的基于运行Microsoft Windows的互联网基本服务.最初是Windows NT版本的可选 ...