题目链接:https://nanti.jisuanke.com/t/30991

Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 3030 Yuan).

However, his owner CXY thinks that take-away food is unhealthy and expensive. So she demands her hamster to fulfill a mission before ordering the take-away food. Then she brings the hamster to a wall.

The wall is covered by square ceramic tiles, which can be regarded as a n * mn∗m grid. CXY wants her hamster to calculate the number of rectangles composed of these tiles.

For example, the following 3 * 33∗3 wall contains 3636 rectangles:

Such problem is quite easy for little hamster to solve, and he quickly manages to get the answer.

Seeing this, the evil girl CXY picks up a brush and paint some tiles into black, claiming that only those rectangles which don't contain any black tiles are valid and the poor hamster should only calculate the number of the valid rectangles. Now the hamster feels the problem is too difficult for him to solve, so he decides to turn to your help. Please help this little hamster solve the problem so that he can enjoy his favorite fried chicken.

Input

There are multiple test cases in the input data.

The first line contains a integer TT : number of test cases. T \le 5T≤5.

For each test case, the first line contains 33 integers n , m , kn,m,k , denoting that the wall is a n \times mn×m grid, and the number of the black tiles is kk.

For the next kk lines, each line contains 22 integers: x\ yx y ,denoting a black tile is on the xx-th row and yy-th column. It's guaranteed that all the positions of the black tiles are distinct.

For all the test cases,

1 \le n \le 10^5,1\le m \le 1001≤n≤105,1≤m≤100,

0 \le k \le 10^5 , 1 \le x \le n, 1 \le y \le m0≤k≤105,1≤x≤n,1≤y≤m.

It's guaranteed that at most 22 test cases satisfy that n \ge 20000n≥20000.

Output

For each test case, print "Case #xx: ansans" (without quotes) in a single line, where xx is the test case number and ansans is the answer for this test case.

Hint

The second test case looks as follows:

样例输入复制

2
3 3 0
3 3 1
2 2

样例输出复制

Case #1: 36
Case #2: 20

题目来源

ACM-ICPC 2018 南京赛区网络预赛

题意:给你一个长方形的方格图,要你找出图中的小方块可以组成矩形的最大个数,黑色方块不能参与矩形的组成,

先输入一个整数T代表样例的个数,接下来分别给出T个样例,对于每一个样例,输入三个数字a,b,c。a,b分别代表长方形方格图的长宽,c代表黑色方格的数量,下来c行每行输入两个整数x,y,代表黑色方格的位置,

思路:这题在比赛的时候看都没有看,也觉得直接写不出,赛后学长给我们讲了一种极其精妙的思路。。。。。

先看代码吧。。。。

#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
bool s[100010][110];
int l[110];
int main(){
int t;
int x,y;
int n,m;
int i,j,k;
int up,mn,cnt;
ll ans;
cnt=0;
scanf("%d",&t);
while(t--){
ans=0;
cnt++;
memset(s,false,sizeof(s));
memset(l,0,sizeof(l));
scanf("%d%d%d",&n,&m,&k);
while(k--){
scanf("%d%d",&x,&y);
s[x][y]=true;
}
for(i=1;i<=n;i++){
up=0;//一列中可以到达的下限位置
for(j=1;j<=m;j++){//一列的开始位置
if(s[i][j]){//该坐标为黑更新该列的下限位置和该行的左极限
l[j]=i;
up=j;
}
mn=i-l[j];
for(k=j;k>up;k--){
if(mn>(i-l[k]))//更新组成新矩形左边可以到的最大位置
mn=i-l[k];
ans+=mn;//该位置可以新增矩阵的数量为左边可以到达的最大值
}
}
}
printf("Case #%d: %lld\n",cnt,ans);
}
}  

可能你刚看到代码的时候会一脸疑惑,这到底是怎么写的,因为我本人的水平太低,可能写在字面上的解释会不太清除。。。。我先把这道题目的核心代码解释一下

for(k=j;k>up;k--){
if(mn>(i-l[k]))//更新组成新矩形左边可以到的最大位置
mn=i-l[k];
ans+=mn;//该位置可以新增矩阵的数量为左边可以到达的最大值
}

  这一段代码就是用来计算可以组成矩形的数量的

我们是以计算以当前位置为基底来计算可以新增矩行的数量

可能这有点难以理解

我们有三个for循环来解决这道题目

第一个循环为1----n

第二个循环为1----m

行为n

列为m

我们计算矩形时是按照先从(1,1)位置开始计算,一直顺序计算到(1,m),然后再从(2,1)位置开始计算,一直顺序计算到(2,m)。。。。。。直到计算到(n,m)位置停止,

对于每次可以新增的矩形数量,我们就可以计算为从当前位置(当前方格块一定为新方格块),以增加已经遍历过的旧的方格的方法来创建新矩形。至于新矩形的计算

字丑请不要介意

ACM-ICPC 2018 南京赛区网络预赛B的更多相关文章

  1. ACM-ICPC 2018 南京赛区网络预赛 J.sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  2. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

  3. 计蒜客 30999.Sum-筛无平方因数的数 (ACM-ICPC 2018 南京赛区网络预赛 J)

    J. Sum 26.87% 1000ms 512000K   A square-free integer is an integer which is indivisible by any squar ...

  4. 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)

    G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K   During tea-drinking, princess, amongst other t ...

  5. 计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)

    A. An Olympian Math Problem 54.28% 1000ms 65536K   Alice, a student of grade 66, is thinking about a ...

  6. ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall

    题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K   Feeling hungry, a cute hamster decides to o ...

  7. ACM-ICPC 2018 南京赛区网络预赛

    轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K   Alice, a student of g ...

  8. ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze

    262144K   There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v ...

  9. ACM-ICPC 2018 南京赛区网络预赛(12/12)

    ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem 计算\(\sum_{i=1}^{n-1}i\cdot i!(MOD\ n)\) \(\sum_{i ...

随机推荐

  1. jqueryd的post传递表单以及取消表单的默认传递

    //取消表单的默认传递: <form method="post" onsubmit="return false;"> 在FORM属性里添加 onsu ...

  2. vue深入响应式原理

    vue深入响应式原理 深入响应式原理 — Vue.jshttps://cn.vuejs.org/v2/guide/reactivity.html 注意:这里说的响应式不是bootsharp那种前端UI ...

  3. docker启动后忘记挂载nvidia-docker-volume的解决方法

    进入 docker 目录 删除 volumes 下的所有文件 重新启动docker 运行nvidia-docker run XXX 来生成volume 修改所有 docker目录下containers ...

  4. 在网页中运用统计Web Service接口

    (2017-02-10 银河统计) 在"统计随机数及临界值Web Service接口"一文中介绍了常用统计分布四类Web Service接口(随机数.分位数.密度函数和累积分布函数 ...

  5. jvm 线上命令

    jstat -gc 40015 查看jvm用的是什么gc算法 java -XX:+PrintCommandLineFlags -version

  6. iOS项目之苹果审核被拒

    解读: 3.2 其他业务模式问题下方列表并非详尽清单,并且您提交的 App 可能会导致我们的政策有所更改或更新,但这里有一些额外的应做事宜和勿做事宜需要您谨记在心: 可以接受 (i)在您的 App 中 ...

  7. Codeforces 438E The Child and Binary Tree - 生成函数 - 多项式

    题目传送门 传送点I 传送点II 传送点III 题目大意 每个点的权值$c\in {c_{1}, c_{2}, \cdots, c_{n}}$,问对于每个$1\leqslant s\leqslant ...

  8. [CodeForces 1141A] Game 23

    题目链接:http://codeforces.com/problemset/problem/1141/A 首先,nn一定要是mm的倍数.否则就无法转换,输出-1: 然后令k=.\frac{m}{n} ...

  9. HTML色码表

    颜色名称及色样表(HTML版)   颜色名 中文名称 Hex RGB 十进制 Decimal     LightPink 浅粉红 #FFB6C1 255,182,193     Pink 粉红 #FF ...

  10. ETCD集群安装实验

    目录 [1.下载二进制程序] [2.安装etcd集群] [3.查询集群状态] [4.存入读取数据] [5.注意事项] [6.参考链接] 简介:     Etcd的官网文档及其在GitHub上的文档,已 ...