UVA 11538-Chess Queen简单排列组合
2015-10-27 10:36
316 查看
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28978
题意: chess中的皇后问题, 在一个n*m的范围内, 两个皇后能够相互攻击的摆放方式.
题意: chess中的皇后问题, 在一个n*m的范围内, 两个皇后能够相互攻击的摆放方式.
#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <algorithm> #include <iostream> #include <queue> #include <map> #include <set> #include <vector> using namespace std; long long min(long long a,long long b) {return a<b?a:b;} long long max(long long a,long long b) {return a>b?a:b;} int main() { long long n,m,i; while(scanf("%lld%lld",&n,&m)!=EOF) { if (!n&&!m) break; long long ans=0; ans+=n*m*(m-1)/2; ans+=m*n*(n-1)/2; long long tmp=0; if (n>m) swap(n,m); for (i=2;i<=n-1;i++) //对角线元素为1到n-1个的情况 { tmp+=i*(i-1)/2; } tmp*=2; //上下两部分对称 tmp+=(m-n+1)*n*(n-1)/2; //对角线元素为n个的情况 tmp*=2; //对角线有两个方向 ans+=tmp; printf("%lld\n",ans*2);//2种颜色互换; } return 0; }
相关文章推荐
- UITableView中用xib实现的cell中的View点击后View消失
- Android更新UI的两种方法——handler与runOnUiThread()
- UITableView中Lable自动换行,Cell自动适应高度
- 【HDOJ】【1005】Number Sequence
- UIBezierPath + bezierPathWithArcCenter
- 苹果在Xcode6中弃用segue的push和model
- String StringBuffer StringBuilder
- JAVA UUID 生成
- Android酷炫实用的开源框架(UI框架)
- VirtualBox Guest Additions
- iOS - UIStatusBar 状态栏设置黑色+白色
- WebService中获取request对象一例
- ActionSheet 显示在 UIWindow,弹出又消失了解决办法
- input 的value值改变事件监听
- input 的value值改变事件监听
- UC/Gui和EmWin的区别:同与不同
- 【第十七篇】easyui-datagrid 导出Excel (在客户端能弹出下载框)
- UIDatePicker的运用
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- 不需要递归将数据格式化 easyui combotree 何各种tree的格式