题目链接: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. K-wolf Number (数位DP)

    题意:求区间内有多少个数满足条件:任意相邻的k个数位都不相等. 思路:老套路 #include<bits/stdc++.h> using namespace std; typedef lo ...

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

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

  3. Object类型的转为String类型

    Map<String, Object> scaleMap = new HashMap(): scaleMap.put("name","张三"); S ...

  4. Oracle 参数文件spfile

    pfile和spfile 概念 ORACLE中的参数文件是一个包含一系列参数以及参数对应值的操作系统文件,可以分为两种类型.它们是在数据库实例启动时候加载的,决定了数据库的物理结构.内存.数据库的限制 ...

  5. vue中父子组件之间的传值、非父子组件之间的传值

    在Vue实例中每个组件之间都是相互独立的,都有自己的作用域,所以组件之间是不能直接获取数据.在项目开发中一个组件可能需要获取另一个组件的值,我们可以通过其他方法间接的获取.所以,获取的方法有以下几种: ...

  6. loj6068. 「2017 山东一轮集训 Day4」棋盘 二分图,网络流

    loj6068. 「2017 山东一轮集训 Day4」棋盘 链接 https://loj.ac/problem/6068 思路 上来没头绪,后来套算法,套了个网络流 经典二分图 左边横,右边列 先重新 ...

  7. CSDN不登录阅读全文(最新更新

    CSDN真的烦...然而没卵用 用stylus加两行css就行了: .article_content{height:auto!important} .hide-article-box{display: ...

  8. Mac OS X 清除DNS缓存

    参考: Flushing your DNS cache in Mac OS X and Linux Mac OS X 清除DNS缓存 根据Mac OS X操作系统的版本选择以下命令: Mac OS X ...

  9. 在 mac iTerm2 中使用 cmd 终端

    在 mac iTerm2 中使用 cmd 终端 主要是因为要在 window 中做一些命令行上的工作, 但又不想切换到整个 window 系统里面去. 在程序和功能中开启 telnet 在服务中启用 ...

  10. Anaconda安装mysqldb模块

    在anaconda里mysqldb是封在mysql-python里的,所以要先在anaconda prompt里运行 conda install mysql-python.(注意要右键选管理员身份)有 ...