题目链接: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. skywalking学习之路---skywalking环境从零搭建部署

    介绍 SkyWalking项目是由华为大牛吴晟开源的个人项目,目前已经加入Apache孵化器.SkyWalking项目的核心目标是针对微服务.Cloud Native.容器化架构提供应用性能监控和分布 ...

  2. C++ STL 顺序容器--list + 关联容器

    list 双向链表,可以双向遍历,既指向前驱节点,又指向后继但不能随机访问任意元素,可动态增加或者减少元素,内存管理自动完成,增加任何元素都不会使迭代器失效, 删除元素时,除了指向当前被删元素的迭代器 ...

  3. Python Rabbit 广播模式

    Exchange 在RabbitMQ下进行广播模式需要用到,exchange这个参数,它会把发送的消息推送到queues队列中,exchange必须要知道,它接下来收到的消息要分给谁,是要发给一个qu ...

  4. 4. Dubbo原理解析-代理之接口定义 (转)

    转载自  斩秋的专栏  http://blog.csdn.net/quhongwei_zhanqiu/article/details/41577159 一:ProxyFactory的接口定义 impo ...

  5. PLSQL远程连接数据库(亲测可试)

    一.准备工具: ORALCE数据库.PLSQL连接工具.确认网络正常 (我是在局域网中的,如果不是局域网,需要去ORACLE安装目录下找到sqlnet.ora 在里面找到 SQLNET.AUTHENT ...

  6. Python3 tkinter基础 Menu add_radiobutton 单选的下拉菜单

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. spring boot2+jpa+thymeleaf增删改查例子

    参考这遍文章做了一个例子,稍微不同之处,原文是spring boot.mysql,这里改成了spring boot 2.Oracle. 一.pom.xml引入相关模块web.jpa.thymeleaf ...

  8. python 基础知识点二

    深浅copy 1对于赋值运算来说,l1与l2指向的是同一个内存地址,所以他们是完全一样的. l1 = [1,2,3,['barry','alex']] l2 = l1 l1[0] = 111 prin ...

  9. 《温故而知新》JAVA基础六

    多态(父子类之间) 对象的多种形态 引用多态 父类的引用可以指向本类对象 父类的引用可以指向子类的对象 方法的多态 创建本类对象时候,调用的方法是本类方法 创建子类对象时候,调用的方法为子类重写的方法 ...

  10. 智能合约 helloworld

    windows 平台 所以直接使用Remix在线编译环境 新建hello.sol文件 编辑如下 Remix 右边侧栏 setting 选择合适的编译器版本 这里选择 0.4.19 文件中输入如下内容  ...