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

  • 2000ms
  • 262144K
 

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组样例,每组样例包括n,m,k三个数,表示n*m的网格,k个网格是有阴影的,接下来k行,每行包括两个数x,y,表示该阴影矩形的坐标,问你总共有多少个矩形,不算阴影的
思路:遍历n*m矩形的每一个点,把这个点当作矩形的右下角的点,以这个点问矩形的右下角,往左遍历,用一个up 数组存起来该点离顶端的高度,up值的总和即为该点的矩形数。具体看代码:
#include<iostream>
#include<string.h>
#include<map>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<cmath>
#include<ctype.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
const ll mod=1e9;
const int maxn=1e5+;
const int maxm=1e2+;
const int maxx=1e4+;
const ll maxe=+;
#define INF 0x3f3f3f3f3f3f
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
int n,m,ca=;
bool a[maxn][maxm];
int up[maxm];
void solve()
{
ll ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(a[i][j]) up[j]=;//有阴影,则高度为0
else up[j]++;//高度的累加
}
for(int j=;j<=m;j++)
{
int minn=mod;//初值无穷大
for(int k=j;k>=;k--)//从该点往左遍历
{
minn=min(minn,up[k]);//最小的高度才是真的能构成的矩形数,可以自己在本子上模拟一下
ans+=minn;
}
}
}
printf("Case #%d: %lld\n",ca++,ans);
}
int main()
{
int t,k,x,y;
cin>>t;
while(t--)
{
memset(a,false,sizeof(a));//
memset(up,,sizeof(up));//表示该点到顶端的高度
cin>>n>>m>>k;
for(int i=;i<k;i++)
{
cin>>x>>y;
a[x][y]=true;//为true表示该点是阴影的
}
solve();
}
return ;
}

ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall的更多相关文章

  1. ACM-ICPC 2018 南京赛区网络预赛 B The writing on the wall(思维)

    https://nanti.jisuanke.com/t/30991 题意 一个n*m的方格矩阵,有的格子被涂成了黑色,问该矩阵中有多少个子矩阵,子矩阵不包含黑色格子. 分析 参考https://bl ...

  2. ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall (暴力)

    题意:一个n*m的方格矩阵,有的格子被涂成了黑色,问该矩阵中有多少个子矩阵,子矩阵不包含黑色格子; 思路:对于一个长为L, 高为H的无黑点矩阵中包含的高为H的子矩阵个数为L+(L-1)+(L-2)+. ...

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

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

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

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

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

    题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...

  6. 计蒜客 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 ...

  7. 计蒜客 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 ...

  8. 计蒜客 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 ...

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

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

随机推荐

  1. Azure Public IP DNS域名

    在某些环境下,PIP是Azure上的一种比较好的解决方案处理一些特殊的环境.比如大量的端口需要打开.向外部的访问非常多等等. 但目前,Azure的Reserved IP address不用应用到PIP ...

  2. 【转】 Pro Android学习笔记(三七):Fragment(2):基础小例子

    目录(?)[-] 小例子运行效果 Pre-step一点准备 Step 1Activity的布局 小例子运行效果 这是一个书名和书简介的例子.运行如下图.Activity由左右两个Fragment组成, ...

  3. python 接口测试字符类型转换

    接口返回数据: print sql[0][10] {"recv_name":"rdgztest_63126","send_name":&qu ...

  4. keepalived+nginx实现双机热备

    keepalived是一个类似于layer3, 4, 5 交换机制的软件,也就是我们平时说的第3层.第4层和第5层交换.Keepalived的作用是检测web服务器的状态,如果有一台web服务器死机, ...

  5. 什么是Nginx?为什么使用Nginx?

    源自 https://blog.csdn.net/yougoule/article/details/78186138 一.前言      为毛要用nginx服务器代理,不直接用tomcat 7.0,还 ...

  6. 【java并发编程艺术学习】(四)第二章 java并发机制的底层实现原理 学习记录(二) synchronized

    章节介绍 本章节主要学习 Java SE 1.6 中为了减少获得锁 和 释放锁 时带来的性能消耗 而引入的偏向锁 和 轻量级锁,以及锁的存储结构 和 升级过程. synchronized实现同步的基础 ...

  7. linux日常管理-screen

    假如一个任务要执行好几天,为了防止中途中断的情况, 在让后台运行的命令后面加一个 nohup会生成一个 .nohup.out文件,会搜集在运行过程中所产生的日志. 比直接后台运行任务的好处是,万一断电 ...

  8. java处理中日文字符串的乱码问题

    ——杂言:前段时间在处理音频预览问题,详见关于audiojs的研究.期间,将远端的音频下载并缓存在本地过程中,涉及到java.io.*的几个操作,发生一些乱码问题. 我以前的处理是将本地的编码转换为U ...

  9. 【机器学习】聚类算法——K均值算法(k-means)

    一.聚类 1.基于划分的聚类:k-means.k-medoids(每个类别找一个样本来代表).Clarans 2.基于层次的聚类:(1)自底向上的凝聚方法,比如Agnes (2)自上而下的分裂方法,比 ...

  10. 面试问题 - SQL 中存储过程与函数的区别

    SQL 中的存储过程与函数没有本质上的区别 函数 -> 只能返回一个变量. 函数可以嵌入到sql中使用, 可以在select 中调用, 而存储过程不行.  但函数也有着更多的限制,比如不能使用临 ...