首页 > 其他 > 详细

三道组合题

时间:2014-10-11 11:20:06      阅读:120      评论:0      收藏:0      [点我收藏+]

uva11538

题意:问一个n*m的棋盘 有多少种方法可以放置两个可以相互攻击的皇后。

讨论下三种情况 横竖斜。  前n项平方和公式: n*(n+1)*(2*n+1)/6

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <iostream>
#include <map>
#include <cstdlib>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include<math.h>
using namespace std;

typedef long long LL;

int main()
{
    LL  n, m;
    while (cin >> n >> m,n||m){
        if (n > m) swap(n, m);
        LL ans = n * m *(m - 1) + n*(n - 1)*m;
        LL ans1 = n*(n - 1) * (2 * n - 1) / 3 - n*(n - 1) + (m - n + 1)*n*(n - 1);
        LL ans3 = ans + ans1 * 2;
        cout << ans3 << endl;
    }
    return 0;
}

 

三道组合题

原文:http://www.cnblogs.com/yigexigua/p/4018374.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!