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), 这是 ...
随机推荐
- PHP libevent函数基本介绍
3.2 主要函数介绍 按照使用libevnet库顺序,看一下相关函数做什么操作. 3.2.1 event_init 调用event_base_new,初始化struct event_base对象 ...
- python脚本7_打印九九乘法表
#打印九九乘法表 for i in range(1,10): s = "" for j in range(1,i+1): s += str(j) + '*' + str(i) + ...
- shell数组中“和@的妙用
#!/bin/bashlist=(4k"8k a bit""16k abc""32k gold"64k)for i in "${l ...
- 重新学习MySQL数据库7:详解MyIsam与InnoDB引擎的锁实现
重新学习Mysql数据库7:详解MyIsam与InnoDB引擎的锁实现 说到锁机制之前,先来看看Mysql的存储引擎,毕竟不同的引擎的锁机制也随着不同. 三类常见引擎: MyIsam :不支持事务,不 ...
- nyi63——树
#include<bits/stdc++.h> using namespace std; int cnt; struct node { int data; int flag; node * ...
- debug调试日志和数据查询
手动删除es文件并释放磁盘空间 1.停掉服务 systemctl stop xsdaemon.service 2.删掉索引 rm -rf /home/storager/c3dceb5e-bacc-4a ...
- Spring入门1. IoC入门实例
Spring入门1. IoC入门实例 Reference:Java EE轻量级解决方案——S2SH 前言: 之前学习过关于Spring的一点知识,曾经因为配置出现问题,而总是被迫放弃学习这些框架技术, ...
- 【jQuery】IE9 jQuery 1.9.1 报 Syntax error,unrecognized expression 错误
<script type="ctrip-template-x" id="ctrip-page-index"> <article class=& ...
- 什么是web?什么是web服务器?什么是应用服务器?
1.什么是Web? 简单来说,Web就是在Http协议基础之上,利用浏览器进行访问的网站.目前来看最常用的意义是指在 Intenet 上和 HTML 相关的部分.换句话说,目前在 Intenet 上通 ...
- vue 错误记录
1.错误信息: You may use special comments to disable some warnings.Use // eslint-disable-next-line to ign ...