当前位置:网站首页>Luogu p2241 statistical square
Luogu p2241 statistical square
2022-04-23 00:32:00 【Soraku7】
Background
1997 First question of the year popularization group
Title Description
There is one n×m Checkerboard with squares , Find out how many squares the square contains 、 Rectangle ( Does not contain a square ).
Input format
a line , Two positive integers n,m(5000n≤5000,m≤5000).
Output format
a line , Two positive integers , Indicate how many squares the square contains 、 Rectangle ( Does not contain a square ).
I/o sample
Input
2 3
Output
8 10
The title is easy to understand , But it still needs some tips to do this topic .
Here is an example of the topic , There is one 2 * 3 The chessboard of , Find the number of squares and rectangles

First look at 1 * 1 The number of squares , Obviously there is 6 individual , 2 * 2 There are... In all 2 individual
Look at the rectangle 1 * 2 The rectangle has 3 individual , 2 * 1 The number of rectangles is 4 individual ,1 * 3 The number of rectangles is 2 individual , Finally, only one large rectangle is left 2 * 3.
If you look at it this way , So we can't seem to find any rules . Now we need to find a law that can find a square and a rectangle . Here's what I think , Let's bring in a coordinate axis , Find the relationship between each point and the number of squares and rectangles

Now from (1 , 1) Start to look at , The number of squares is 1 , The number of rectangles is 0, Sum to 1
(2 , 1), At this time, compared with (1 , 1) Compare to , There are too many squares 1 , There are too many rectangles 1 , It's too much 2
(3 , 1), At this time, compared with (2 , 1) Compare to , There are too many squares 1 , There are too many rectangles 2 , It's too much 3
Now let's summarize the rules , If you don't understand this Law , Or if you don't understand it, you can test it according to the rules I put forward
The number of squares added should be (x , y) The smaller of the coordinates , The total increase of square and rectangle should be x * y.
It seems that there is such a simple and convenient rule , It seems that we can calculate the number of squares in the chessboard . The number of rectangles, of course, we can use the number of all rectangles minus the number of squares , Nature is the number of rectangles .
The code here is relatively simple
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
long long n, m;
long long squ = 0, sum = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
squ += min(i, j);
sum = sum + i * j;
}
}
cout << squ << " " << sum - squ;
return 0;
}
, Just a few comments
版权声明
本文为[Soraku7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230028507616.html
边栏推荐
- (transfer) Aspose Working with document in words Programming Guide
- [image classification] reproduce senet with the shortest code. Xiaobai must be collected (keras, tensorflow2. X)
- Deletes all specified elements in the vector
- How do programmers find jobs? What if it becomes more and more difficult for programmers to find a job?
- The story of tidb and I met unprepared, but I wanted to say how lucky I was to meet you
- Misunderstanding of indexlookup
- 倍福EL6631和西门子通信profinet出现报错解决方案
- EL2521模块控制步进驱动器
- 倍福Scaling factor因子计算
- EL2124模块接线和引脚含义
猜你喜欢

(transfer) Aspose Working with document in words Programming Guide

API post, the interface document generation tool, is amazing

MySQL installation and basic use tutorial

Mitsubishi fx5u configures iebasic setting of mr-je-c servo driver

植被物候参数遥感研究进展(好文分享)
![[AI vision · quick review of today's sound acoustic papers, issue 4] Thu, 21 APR 2022](/img/88/7c4f2f67c0b0aec70a057f43fff1ea.png)
[AI vision · quick review of today's sound acoustic papers, issue 4] Thu, 21 APR 2022

(transfer) Aspose Introduction to DOM tree structure, node class inheritance relationship and description of words Programming Guide

Two methods are used to realize mongodb self increment ID, and the second one is recommended

Detailed introduction of Mitsubishi mr-je-c servo application

MySQL运行workbench报错TRunTimeError
随机推荐
ArcMAP 使用绘图工具添加注记
倍福两台CX控制器之间添加路由
[play with lighthouse] build a temporary mailbox system that can be collected and destroyed immediately
ArcGIS 城市生活区用地适宜性评价(一)
【征文大赛】TiDB 社区专栏第一届征文大赛,快来一次性集齐所有周边吧!
在Google工作的十年,也是我开心的十年
MP2459被完美替代内部集成有功率MOSFET管FS2459的60V0.5A降压IC
Unittest unit test (6)
while (n-- > 0) 的用法
JVM performance tuning 1
ArcGIS urban living area land suitability evaluation (II)
Migrate AWS S3 data to tidb cloud cluster
USPS dataset_ Kmeans Usage Summary
EL2124模块接线和引脚含义
三菱MR-JE-C伺服应用详细介绍
[C#]给地球点颜色看看
ArcGIS 城市生活区用地适宜性评价(三)
EL2521模块控制步进驱动器
Misunderstanding of indexlookup
倍福NC轴走速度模式