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;
    }





  • 相关阅读:
    .net4.5使用async和await异步编程实例
    并行开发系列 Plinq等
    改善C#程序的建议9:使用Task代替ThreadPool和Thread
    C# Task 用法
    Task
    C#委托的介绍(delegate、Action、Func、predicate)(转)
    ACTION与FUNC
    C#二叉树简易实例
    一些简单的算法
    教你如何写thinkphp多表查询语句
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3000822.html
Copyright © 2011-2022 走看看