【链接】点击打开链接


【题意】


给你一个0..n和0..m的区域.
你可以选定其中的4个点,然后组成一个正方形.
问你可以圈出多少个正方形.
(正方形的边不一定和坐标轴平行)

【题解】


首先,考虑只和坐标轴平行的情况
长度为L的正方形有(N-L+1)*(M-L+1)个.
然后引入一个bounding box的概念。
一个正方形的bounding box,指的是一个最小的包括了正方形的4个点的一个矩形.
矩形的边都是和坐标轴平行的
正方形的bounding box都是正方形!
这样,我们刚才枚举的和坐标轴平行的正方形就有用了。
相当于我们在枚举所有正方形的bouding box.
那么一个长为L的boungding box正方形,里面包含多少个小正方形呢?
答案是L个,因为我们能在一条边里面的L-1个点中任选一个点,一旦这个一个点选定之后,boungding box对应的正方形的其他3个点就确定了.
可以保证其他3个点是在这个boungding box的另外3条边上的
然后还有这个bounding box本身一个正方形.
这样我们只要枚举boungding box的长度L,算出它的个数有多少个,乘上L加到答案里就好。

【错的次数】


0

【反思】


用bounding box的概念,来算出所有的正方形。
正方形的boungding box还是一个正方形.
整点上,枚举出了bouding box,则bounding box为这个的正方形个数就是 boundingbox的长度.

【代码】

/*

*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
#include <bitset>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ld long double
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rf(x) scnaf("%lf",&x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size())
#define ld long double typedef pair<int, int> pii;
typedef pair<LL, LL> pll; //mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110;
const LL MOD = 1e9 + 7;
LL ans = 0; int n, m; int main() {
//Open();
//Close();
ri(n), ri(m);
rep1(i, 1, min(n, m)) {
ans += (LL)i*(n - i + 1)*(m - i + 1);
ans %= MOD;
}
ol(ans); puts("");
return 0;
}

【CS Round #44 (Div. 2 only) D】Count Squares的更多相关文章

  1. 【CS Round #44 (Div. 2 only) A】Frequent Numbers

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 大水题 [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #include <cstdio> #include &l ...

  2. 【CS Round #44 (Div. 2 only) B】Square Cover

    [链接]点击打开链接 [题意] 给你一个n*m的矩形,让你在其中圈出若干个子正方形,使得这些子正方形里面的所有数字都是一样的. 且一样的数字,都是在同一个正方形里面.问你有没有方案. [题解] 相同的 ...

  3. 【CS Round #44 (Div. 2 only) C】Check DFS

    [链接]点击打开链接 [题意] 给你一个n节点,m条边的无向联通图. 给你一个节点访问的顺序.(1..n的排列) 你可以改变每个点优先访问的出度.(但必须按照dfs的规则); 问你能不能按照所给的访问 ...

  4. 【CS Round #36 (Div. 2 only) A】Bicycle Rental

    [题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...

  5. 【CS Round #37 (Div. 2 only) D】Reconstruct Graph

    [Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...

  6. 【CS Round #37 (Div. 2 only) B】Group Split

    [Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...

  7. 【CS Round #37 (Div. 2 only) A】Boring Number

    [Link]:https://csacademy.com/contest/round-37/task/boring-number/ [Description] 让你找离平均数最近的一个数的下标; [S ...

  8. 【CS Round #39 (Div. 2 only) D】Seven-segment Display

    [Link]:https://csacademy.com/contest/round-39/task/seven-segment-display/ [Description] 0..9各自有一个数字, ...

  9. 【CS Round #39 (Div. 2 only) C】Reconstruct Sum

    [Link]:https://csacademy.com/contest/round-39/task/reconstruct-sum/ [Description] 给你一个数字S; 让你找有多少对A, ...

随机推荐

  1. 玩转 Jupyter Notebook (CentOS)

    Jupyter Notebook 简介 Jupyter Notebook 是一个开源的 Web 应用程序,可以用来创建和共享包含动态代码.方程式.可视化及解释性文本的文档.其应用于包括:数据整理与转换 ...

  2. 【Henu ACM Round#14 A】Vitaly and Night

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 连续两个如果不全是0就递增cnt [代码] #include <bits/stdc++.h> using namespa ...

  3. UVALive 6869 Repeated Substrings

    Repeated Substrings Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Descri ...

  4. Linux下使用fstatfs/statfs查询系统相关信息

    Linux下使用fstatfs/statfs查询系统相关信息 1.   功能 #include < sys/statfs.h > int statfs(const char *path, ...

  5. sql-server 2005数据库文件恢复(检測到基于一致性的逻辑 I/O 错误)

    今天sql-server数据库突然报错: SQL Server 检測到基于一致性的逻辑 I/O 错误 校验和不对(应为: 0x7c781313,但实际为: 0x67a313c9). 在文件 'C:\P ...

  6. 生成ssh公有密钥而且注冊到Github Generate ssh rsa keys and register public key on Github

    私有密钥和公有密钥是成对的两个文件,私有文件保存在自己的本机,公有密钥保存到还有一端的server,站点等. github就是一种站点. 仅仅有保存了私有密钥的机器才干訪问远程的server等. 使用 ...

  7. BZOJ 2037 区间DP

    跟POJ 3042是一个类型的http://blog.csdn.net/qq_31785871/article/details/52954924 思路: 先排个序 (把初始位置也插进去) f[i][j ...

  8. C#List<string>和string[]之间的相互转换

     一.LIST概述 所属命名空间:System.Collections.Generic      public class List<T> : IList<T>, IColle ...

  9. Ubuntu+PyQt5+Python3.6+Qt Designer 实现可视化窗口的编辑

    一.为什么写这片博文 近期将实验室的电脑的OS换成了ubuntu,想对linux进一步的了解和使用.在使用的过程中想用python+pyqt5写一个音乐播放器和视频播放器(这也是linux的乐趣所在) ...

  10. 今日SGU 5.8

    SGU 109 题意:一个n*n的矩形,起点在1,1然后每次给你一个操作,走ki步,然后你可以删除任意一个点这次步走不到的,删了就不能再走了,然后问构造这种操作,使得最后删除n*n-1个点 剩下一个点 ...