【链接】点击打开链接


【题意】


给你一个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. noip 2018 day1 T2 货币系统 完全背包

    Code: #include<cstdio> #include<string> #include<cstring> #include<algorithm> ...

  2. WebAssembly学习(六):AssemblyScript - 限制与类型

    一.限制 将无类型的JavaScript编译为WebAssembly没有意义,因为它最终会导致运行其中较慢的一个JavaScript. 相反,AssemblyScript专注于WebAssembly擅 ...

  3. Js 中的i++ 和 ++i 的区别

    首先碰见  i++ 和 ++i 会一脸蒙蔽 感觉没什么区别,都是相加  , 但是  输出的值是不同!!! 来奉上代码来进行比较 var i = 1; var a = i++; //a = 1; 此时i ...

  4. Hexo 搭建

    前提 最近准备搭建一个博客平台,也看了很多开源的博客框架.比如Solo.wordpress等框架.自已曾经也在cnblog发布过几篇文章.东写写西写写.杂乱无章的.后续可以写一个自动同步各平台的程序~ ...

  5. WPF 让普通 CLR 属性支持 XAML 绑定(非依赖属性),这样 MarkupExtension 中定义的属性也能使用绑定了

    原文:WPF 让普通 CLR 属性支持 XAML 绑定(非依赖属性),这样 MarkupExtension 中定义的属性也能使用绑定了 版权声明:本作品采用知识共享署名-非商业性使用-相同方式共享 4 ...

  6. 一个Web报表项目的性能分析和优化实践(六):设置MySQL的最大连接数(max_connections)

    在上一篇文章中"一个Web报表项目的性能分析和优化实践(二):MySQL数据库连接不够用(TooManyConnections)问题的一次分析和解决案例"提到,项目中新增几个数据库 ...

  7. 从设计到实现,一步步教你实现Android-Universal-ImageLoader-辅助类

    通过前面几篇博文.我们分析了 AUI 的缓存.工具类.显示与载入这几个方面的代码.今天呢,我们继续研究 AUI 的源代码,学习当中的核心辅助工具类. 希望大家能在里面学到东西哈. Download 要 ...

  8. uva725(除法)

    Description Write a program that finds and displays all pairs of 5-digit numbers that between them u ...

  9. 调用google翻译

    1. [代码]maven依赖     ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <dependency>     <groupId>org.a ...

  10. 如何动态改变audio的播放的src

    如何动态改变audio的播放的src 一.总结 一句话总结:js方式在请求外部网站的时候行,php方式在请求内外部资源都行.因为php走在js前面,所以问题可以从php方面想办法. 1.如何使用js控 ...