UVa11538 - Chess Queen
来源:互联网 发布:windows如何设置锁屏 编辑:程序博客网 时间:2024/06/11 02:07
Problem A
Chess Queen
Input: Standard Input
Output: StandardOutput
You probably know how the game ofchess is played and how chess queen operates. Two chess queens are in attackingposition 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(2x2) chess board. They can be in attacking positions in 12 ways, these areshown in the picture below:
Figure: in a (2x2) chessboard 2 queens can be in attacking position in 12 ways
Given an (NxM)board you will have to decide in how many ways 2 queens can be in attackingposition in that.
Input
Input file can contain up to 5000lines of inputs. Each line contains two non-negative integers which denote thevalue ofM 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 produceone line of output. This line contains an integer which denotes in how manyways two queens can be in attacking position in an (MxN) board, wherethe values ofM and N came from the input. All output values willfit in 64-bit signed integer.
SampleInput Output for Sample Input
2 2
100 223
2300 1000
0 0
12
10907100
11514134000
import java.io.FileInputStream;import java.io.InputStreamReader;import java.io.BufferedReader;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.io.StreamTokenizer;public class Main {private static final boolean DEBUG = false;private BufferedReader cin;private PrintWriter cout;private StreamTokenizer tokenizer;private long m, n;public void init() {try {if (DEBUG) {cin = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\OJ\\uva_in.txt")));} else {cin = new BufferedReader(new InputStreamReader(System.in));}cout = new PrintWriter(new OutputStreamWriter(System.out));tokenizer = new StreamTokenizer(cin);} catch (Exception e) {e.printStackTrace();}}public String next(){ try {tokenizer.nextToken();if (tokenizer.ttype == StreamTokenizer.TT_EOF) return null;else if (tokenizer.ttype == StreamTokenizer.TT_NUMBER) return String.valueOf((int)tokenizer.nval);else return tokenizer.sval;} catch (Exception e) {e.printStackTrace();return null;}}public boolean input() {m = Long.parseLong(next());n = Long.parseLong(next());if (m == 0 && n == 0) return false;if (m < n) {long tmp = m; m = n;n = tmp;}return true;}public void solve() {long ans;ans = m * (m - 1) * n + n * (n - 1) * m + (n * (n - 1) * (2 * n - 1) / 6 - (n - 1) * n / 2) * 4 + 2 * n * (n - 1) * (m - n + 1);cout.println(ans);cout.flush();}public static void main(String[] args) {Main solver = new Main();solver.init();while (solver.input()) {solver.solve();}}}
- UVA11538(Chess Queen )
- UVa11538 - Chess Queen
- UVA11538-Chess Queen
- uva11538 Chess Queen
- Chess Queen uva11538 解题报告
- uva11538 Chess Queen(组合数学)
- uva11538 - Chess Queen(象棋中的皇后)
- 【UVA11538】Chess Queen——简单组合
- UVa 11538 - Chess Queen
- Chess Queen UVA 11538
- UVA 11538 Chess Queen
- Uva-11538-Chess Queen
- UVa 11538 Chess Queen
- UVa 11538 - Chess Queen
- uva 11538 Chess Queen
- UVA 11538 Chess Queen
- UVA 11538 - Chess Queen
- uva 11538 Chess Queen
- MySql下视图的创建
- POJ2109
- 自旋锁 死锁
- hdu 4911 Inversion
- android中特殊应用跟系统特殊功能协助配合通讯问题
- UVa11538 - Chess Queen
- 超级手机病毒算是病毒吗?
- 不断....
- 【HDU4911】分治求逆序数
- oracle 的完全卸载
- hdoj 1257 最少拦截系统 【贪心】
- 给MFC加入声音
- Oracle性能调优--并行(parallel)
- Android Launcher分析