题目链接: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. 代码实现跟控制器跳转到storyBoard

  2. android获取时间差的方法

    本文实例讲述了android获取时间差的方法.分享给大家供大家参考.具体分析如下: 有些时候我们需要获取当前时间和某个时间之间的时间差,这时如何获取呢? 1. 引用如下命名空间: import jav ...

  3. Poj 1316 Self Numbers(水题)

    一.Description In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called se ...

  4. keepalived+nginx实现双机热备

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

  5. 2 ubuntu 16.04 安装Elastic Stack

    一: 安装JAVA8          添加ppa sudo add-apt-repository ppa:webupd8team/java sudo apt-get update 安装oracle- ...

  6. 微服务学习一 微服务session 管理

    集群和分布式架构中: session管理有三种方法: 1: Cookie: 将Session对象保存在Cookie,保存在浏览器端.浏览器发送请求的时候,会把整个session放在请求里一起发送到se ...

  7. [jQuery] 按回车键实现登录

    Jquery按回车键提交实现登录的方式分为两种: 1.按钮提交 2.表单提交 1.按钮提交 $("#LoginIn").off('click').on('click', funct ...

  8. java中的equals方法

    这个方法首先比较的是两个对象的地址是否相同,如果相同直接返回true, 否则, (1)如果是string类型的先比较是否是string类型,是的话,再比较是否长度相同,相同的话再比较,每个字符是否相同 ...

  9. github 换行符自动转换功能

    最近想把自己的一个Qt工程同步到github上,但是当自己把代码从仓库中签出来的时候编译的时候总是出现一些很奇葩的错误,一开始以为是源文件编码的问题,改了编码以后问题还是没有解决,我比较了一下两个工程 ...

  10. mysql设置远程登录

    服务器上,我们刚安装好MySQL后,是没有办法直接远程的,它只支持本地登录.所以我们必须要对刚安装好的MySQL进行设置,允许远程登录. 1. 使用“mysql -uroot -p”命令可以连接到本地 ...