zoukankan      html  css  js  c++  java
  • UVA 11538(Chess Queen矩阵对角线长度)

    Problem A
    Chess Queen
    Input:
    Standard Input

    Output: Standard Output

    王后互相攻击的前提是在一行,一列,或一对角线。:

     

    在 (NxM) 的棋盘上 2 王后互相攻击,求方案数.

    Input

    输入数据不超过 5000 行 ,每行为M and N (0< M, N£106) ,数据以0 0结尾.

    Output

    每行一个整数表示方案数,保证它在u64范围内.

    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


    首先,一个矩形的长宽若为m,n(m>=n)

    那么它一个方向的对角线应为1..(n-1)各2条,n有(m-n+1)条

    知道这个的化,本题就转化为,在一列一行或一对角线任取2点,有几种取法。

    #include<cstdio>
    #include<algorithm>
    #include<functional>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    using namespace std;
    #define MAXN (1000000+10)
    unsigned long long n,m;
    int main()
    {
    	while (cin>>n>>m&&n&&m)
    	{
    		if (n>m) swap(n,m);
    		cout<<n*m*(n+m-2)+2*n*(n-1)*(3*m-n-1)/3<<endl;
    	}
    	return 0;
    }





  • 相关阅读:
    nginx 自启动脚本
    debian开机启动管理
    vagrant up connection time out
    vagrant在windows下的使用
    Office Web Apps Server
    邻接表模型中的节点移动
    Managing Hierarchical Data in MySQL(邻接表模型)[转载]
    play mp3 in c#
    2014年5月份第3周51Aspx源码发布详情
    2014年5月份第2周51Aspx源码发布详情
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3000822.html
Copyright © 2011-2022 走看看