题目链接: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. JAVA JDK 环境变量配置--简单图解

    Linux下的Jmeter运行测试 本文主要介绍Jmeter脚本如何在Linux通过no GUI的方式运行.总共分三部分: 1.Linux下JDK的安装及环境变量的配置 2.Linux下Jmeter的 ...

  2. nginx-高并发配置 第七章

    一 .nginx 服务配置优化: 1.nginx进程数,建议按照cpu数目来指定,一般为它的倍数.worker_processes 定义了nginx对外提供web服务时的worker进程数.最优值取决 ...

  3. Python 协程实现socket并发

    socket多并发 socket可以实现单个客户端进行请求访问,它可以通过socketserver来实现并发功能呢,socketserver是通过启用多线程实现并发,在这里我们也可以通过gevent协 ...

  4. CentOS 6.5优化开机启动服务

    使用chkconfig命令列举出所有服务,配合管道筛选出开机默认启动的服务,再去掉level0(关机).level4(无意义)和level6(重启)的显示,使结果更直观. chkconfig | gr ...

  5. shell爬虫--抓取某在线文档所有页面

    在线教程一般像流水线一样,页面有上一页下一页的按钮,因此,可以利用shell写一个爬虫读取下一页链接地址,配合wget将教程所有内容抓取. 以postgresql中文网为例.下面是实例代码 #!/bi ...

  6. Java解决异常之try、catch、finally、throw、throws&log4j记录日志步骤

    知识点一.多重catch引发多种类型的异常排列catch 语句的顺序:先子类后父类 发生异常时按顺序逐个匹配只执行第一个与异常类型匹配的catch语句二.异常分类异常分为运行时异常和检测异常运行时异常 ...

  7. 解决apache httpd列出目录列表中文乱码问题

    问题: 找了好几个方法都不对, 很多都是说修改AddDefaultCharset字段的, 下面是新的方法, 新测可行 在httpd.conf下, 随便找个地方把下面这个字段扔上去, 重启即可 Inde ...

  8. ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails ()

    centos7.5 删除表空间文件失败 问题: mysql> alter table country discard tablespace; ERROR 1451 (23000): Cannot ...

  9. topcoder srm 590 div1 (max_flow_template)

    problem1 link 对于每一个,找到其在目标串中的位置,判断能不能移动即可. problem2 link 如果最后的$limit$为$11=(1011)_{2}$,那么可以分别计算值为$(10 ...

  10. Windows下Python安装numpy+mkl,Scipy和statsmodels

    最近做时间序列分析需要用到Python中的statsmodels,但是安装过程中遇到很头疼的问题,Google.Stackover各种都没有找到合适的解决办法,而且貌似还有很多同学也在吐槽Window ...