UVA11538 Chess Queen】的更多相关文章

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2533 题意:在n*m的棋盘上放两个(黑和白)相互攻击的皇后,求有多少种方法?  0<=(n,m)<=10e6; 下图是2*2的方案数12: 很明显要按行列还有对角三种来考虑,每种的方案数相加即可: 每一行我们要从m个格子中选择2个进行放所以方案数是m*(m-1),共有…
题意 给一个\(n \times m\)的棋盘,输出有多少种方法放置两个互相攻击的皇后. \(n,m \leq 10^6\) 分析 参照刘汝佳的题解. 横.竖.斜三种情况互不相干,加法原理统计. 横竖都好计算,斜着需要推一推. 然后注意溢出问题. 代码 #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<set> #include<ma…
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 qu…
A Chess Queen Problem A Chess Queen  Input: Standard Input Output: Standard Output 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 diagona…
Problem A Chess Queen Input: Standard Input Output: Standard Output 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 bo…
传送门 Description 给你一个n*m的棋盘,在棋盘上放置一黑一白两个皇后,求两个皇后能够互相攻击的方案个数 Input 多组数据,每组数据包括: 一行,为n和m 输入结束标志为n=m=0. Output 对于每组数据,输出: 对应的放置方案数 Sample Input Sample Output Hint n,m≤1e6,n和m不全为1.保证最终答案在long long int范围之内 两个皇后能相互攻击,当且仅当他们在同一列,同一行,或同一斜线上. 黑白两个皇后位置相反算两种不同的方…
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2533 三个方向, 横,竖,对角线~ #include<iostream> #include<cstdio> using namespace std; int main() { long long int n,m; while(scanf("%lld%l…
题目链接 题意:给出m行n列的棋盘,当两皇后在同行同列或同对角线上时可以互相攻击,问共有多少种攻击方式. 分析:首先可以利用加法原理分情况讨论:①两皇后在同一行:②两皇后在同一列:③两皇后在同一对角线( / 或 \ ): 其次利用乘法原理分别讨论: ①同一行时(A),先选某一行某一列放置其中一个皇后,共m*n种情况:其次在选出的这一行里的其他n-1个位置中选一个放另一个皇后:共m*n*(n-1)种情况: ②同一列时(B)情况相同,为n*m*(m-1)种情况: ③同一对角线(D)上时,先讨论 /…
考虑把皇后放在同一横排或者统一纵列,答案为nm(m-1)和nm(n-1),显然. 考虑同一对角线的情况不妨设,n<=m,对角线从左到右依次为1,2,3,...,n-1,n,n,n,...,n(m-n+1个n),n-1,n-2,...,2,1 还有另一个方向的对角线,所以算出来之后要乘二. 即答案为2(2*Σ(i to n-1) (i(i-1))    +   (m-n+1)n(n-1)) Σ(i to n-1) (i(i-1))怎么算呢? 可以拆成Σi² - Σi , i²的前缀和公式我就不推了…
题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种. 析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是行和列的,然后再算对角线,对角线是从2-min(m, n)的, 然后就能算出来. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <strin…
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 // // Created by Candy on 24/10/2016. // Copyright © 2016 Candy. All rights reserved. // #include <iostream> #include <cstdio> #include <cst…
#include <stdio.h> #include <stdlib.h> /* this code is used to cope with the problem of the eight queens. * array borad[9][9] is a virtual borad. * line 0 and volumn 0 is ignored. * at first we find a place to set a queen on it, then mark this…
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to…
题目链接: http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test4 secondsmemory limit per test256 megabytes 问题描述 Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that pla…
D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. T…
A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and…
Chess  Almost everyone knows the problem of putting eight queens on an  chessboard such that no Queen can take another Queen. Jan Timman (a famous Dutch chessplayer) wants to know the maximum number of chesspieces of one kind which can be put on an  …
D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. T…
A. A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A…
Anton and Chess time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. H…
A. A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A…
D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. T…
题目链接:http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Anton likes to play chess. Also, he likes to do programming. That is why…
D. Vasya and Chess   Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell…
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard output Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the…
Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead. The first task he faced is to check…
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1597    Accepted Submission(s): 1088 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids lab…
Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the mov…
A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3917   Accepted: 1596 Description Let's design a new chess game. There are N positions to hold M chesses in this game. Multiple chesses can be located in the same position. The…
Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 24    Accepted Submission(s): 10 Problem Description 小度和小良最近又迷上了下棋.棋盘一共有N行M列,我们可以把左上角的格子定为(1,1),右下角的格子定为(N,M).在他们的规则中,“王”在棋盘上的走法遵循十字路线.也就是说,…