ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall
题目链接: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
题目来源
#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的更多相关文章
- ACM-ICPC 2018 南京赛区网络预赛 B The writing on the wall(思维)
https://nanti.jisuanke.com/t/30991 题意 一个n*m的方格矩阵,有的格子被涂成了黑色,问该矩阵中有多少个子矩阵,子矩阵不包含黑色格子. 分析 参考https://bl ...
- ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall (暴力)
题意:一个n*m的方格矩阵,有的格子被涂成了黑色,问该矩阵中有多少个子矩阵,子矩阵不包含黑色格子; 思路:对于一个长为L, 高为H的无黑点矩阵中包含的高为H的子矩阵个数为L+(L-1)+(L-2)+. ...
- ACM-ICPC 2018 南京赛区网络预赛 J.sum
A square-free integer is an integer which is indivisible by any square number except 11. For example ...
- ACM-ICPC 2018 南京赛区网络预赛 E题
ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...
- ACM-ICPC 2018 南京赛区网络预赛B
题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...
- 计蒜客 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 ...
- 计蒜客 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 ...
- 计蒜客 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 ...
- ACM-ICPC 2018 南京赛区网络预赛
轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K Alice, a student of g ...
随机推荐
- debian服务查询
1.查询 用root身份执行service --status-all查看所有服务的状态 "+" started "-" stopped "?" ...
- findBug 错误修改指南
1. EC_UNRELATED_TYPESBug: Call to equals() comparing different types Pattern id: EC_UNRELATED_TYPE ...
- Poj_1002_java解决
一.Description 电话号码的标准格式是七位十进制数,并在第三.第四位数字之间有一个连接符.电话拨号盘提供了从字母到数字的映射,映射关系如下: A, B, 和C 映射到 2 D, E, 和F ...
- Poj_1045
这道题难点在于基本物理知识和数学的结合. 得出公式后再code,那就是小菜一碟了. import java.util.Scanner; import java.lang.Math; public cl ...
- HDOJ1251(前缀匹配---分块查找&map应用)
分块查找算法 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm ...
- Linker Tools Error LNK2001
https://msdn.microsoft.com/en-us/library/f6xx1b1z.aspx https://www.cnblogs.com/runningRain/p/5674833 ...
- shell 自动删除n天前备份
Linux自动删除n天前备份Linux是一个很能自动产生文件的系统,日志.邮件.备份等.因此需要设置让系统定时清理一些不需要的文件.语句写法: find 对应目录 -mtime +天数 -na ...
- Statement, PreparedStatement和CallableStatement的区别
Statement用于执行不带参数的简单SQL语句,并返回它所生成的结果,每次执行SQL豫剧时,数据库都要编译该SQL语句. Satatement stmt = conn.getStatement() ...
- 21. 从一道CTF靶机来学习mysql-udf提权
这次测试的靶机为 Raven: 2 这里是CTF解题视频地址:https://www.youtube.com/watch?v=KbUUn3SDqaU 此次靶机主要学习 PHPMailer 跟 mymq ...
- 8. CTF综合靶机渗透(一)
靶机说明 虚拟机难度中等,使用ubuntu(32位),其他软件包有: PHP apache MySQL 目标 Boot to root:从Web应用程序进入虚拟机,并获得root权限. 运行环境 靶机 ...