Uva 11538 - Chess Queen

时间:2022-05-14 07:59:21

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2533

Root

11538 - Chess Queen

Time limit: 2.000 seconds

  You probably know how the game of chess is played and how chess queen operates. Two chess queens are in attacking position when they are on same row, column or diagonal of a chess board. Suppose two such chess queens (one black and the other white) are placed on (2 × 2) chess board. They can be in attacking positions in 12 ways, these are shown in the picture below:

Uva 11538 - Chess Queen

  Figure: in a (2 × 2) chessboard 2 queens can be in attacking position in 12 ways Given an (N × M) board you will have to decide in how many ways 2 queens can be in attacking position in that.

Input

  Input file can contain up to 5000 lines of inputs. Each line contains two non-negative integers which denote the value of M and N (0 < M, N ≤ 106 ) respectively. Input is terminated by a line containing two zeroes. These two zeroes need not be processed.

Output

  For each line of input produce one line of output. This line contains an integer which denotes in how many ways two queens can be in attacking position in an (M × N) board, where the values of M and N came from the input. All output values will fit in 64-bit signed integer.

Sample Input

2 2

100 223

2300 1000

0 0

Sample Output

12

10907100

11514134000

分析;

公式: n*m*(m+n-2)+2*n*(n-1)*(3*m-n-1)/3 。

AC代码:

 // UVa11538 Chess Queen

 #include<iostream>

 #include<algorithm>

 using namespace std;

 int main() {

   unsigned long long n, m; // 最大可以保存2^64-1>1.8*10^19

   while(cin >> n >> m) {

     if(!n && !m) break;

     if(n > m) swap(n, m); // 这样就避免了对n<=m和n>m两种情况分类讨论

     cout << n*m*(m+n-)+*n*(n-)*(*m-n-)/ << endl;

   }

   return ;

 }

吐槽一下:uva 上面看不了自己的代码,只能自己把每个代码都保存下来咯,,,Orz

Uva 11538 - Chess Queen的更多相关文章

  1. 组合数学 UVa 11538 Chess Queen

    Problem A Chess Queen Input: Standard Input Output: Standard Output You probably know how the game o ...

  2. uva 11538 Chess Queen&lt&semi;计数&gt&semi;

    链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  3. 【基本计数方法---加法原理和乘法原理】UVa 11538 - Chess Queen

    题目链接 题意:给出m行n列的棋盘,当两皇后在同行同列或同对角线上时可以互相攻击,问共有多少种攻击方式. 分析:首先可以利用加法原理分情况讨论:①两皇后在同一行:②两皇后在同一列:③两皇后在同一对角线 ...

  4. 【组合计数】UVA - 11538 - Chess Queen

    考虑把皇后放在同一横排或者统一纵列,答案为nm(m-1)和nm(n-1),显然. 考虑同一对角线的情况不妨设,n<=m,对角线从左到右依次为1,2,3,...,n-1,n,n,n,...,n(m ...

  5. UVa 11538 Chess Queen &lpar;排列组合计数&rpar;

    题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种. 析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是 ...

  6. UVa11538 A Chess Queen

    A Chess Queen Problem A Chess Queen  Input: Standard Input Output: Standard Output You probably know ...

  7. 【策略】UVa 278 - Chess

    Chess  Almost everyone knows the problem of putting eight queens on an  chessboard such that no Quee ...

  8. UVA11538 - Chess Queen(数学组合)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  9. uva 11195 Another queen &lpar;用状态压缩解决N后问题&rpar;

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. iOS 图片大小压缩 图片尺寸处理

    图片的压缩其实是俩概念,1.是 “压” 文件体积变小,但是像素数不变,长宽尺寸不变,那么质量可能下降,2.是 “缩” 文件的尺寸变小,也就是像素数减少.长宽尺寸变小,文件体积同样会减小. 这个 UII ...

  2. CAF(C&plus;&plus; actor framework)&lpar;序列化之结构体,任意嵌套STL)(一)

    User-Defined Data Types in Messages(用户自定义类型)All user-defined types must be explicitly “announced” so ...

  3. &lbrack;转&rsqb; Symbol对象

    GIS中的离散实体有三种:点.线.面,在ArcEngine中用三种符号对应表示,分别是:MarkSymbol.LineSymbol和FillSymbol.此外还有TextSymbol用于文字标注,3D ...

  4. C&num; foreach循环较for循环的优势与劣势

    一.foreach循环的优势 C#支持foreach关键字,foreach在处理集合和数组相对于for存在以下几个优势: 1.foreach语句简洁 2.效率比for要高(C#是强类型检查,for循环 ...

  5. KVM网页管理工具WebVirtMgr部署

    KVM-WebVirtMgr 0ther https://github.com/retspen/webvirtmgr/wiki System Optimization(Only CentOS6.X) ...

  6. nova创建虚拟机源码分析系列之六 api入口create方法

    openstack 版本:Newton 注:博文图片采用了很多大牛博客图片,仅作为总结学习,非商用.该图全面的说明了nova创建虚机的过程,从逻辑的角度清晰的描述了前端请求创建虚拟机之后发生的一系列反 ...

  7. RSA 非对称加密【转】

    演示代码:https://pan.baidu.com/s/10rfSUUDEEHvCDEYH0oEVCw Base64工具类,可以让rsa编码的乱码变成一串字符序列 1 package com.uti ...

  8. Eslint 从入门到放弃

    https://blog.csdn.net/walid1992/article/details/54633760

  9. 【python】安装pymongo时出错

    在python2.7的环境下,使用pip install pymongo安装模块报以下错误: Could not install packages due to an EnvironmentError ...

  10. 20162327WJH第一次实验——线性结构

    20162327WJH第一次实验--线性结构 实 验 报 告 实 验 报 告 课程:程序设计与数据结构 班级: 1623 姓名: 王旌含 学号:20162327 成绩: 2分 指导教师:娄嘉鹏 王志强 ...