ACM-ICPC 2018 南京赛区网络预赛 B The writing on the wall(思维)
https://nanti.jisuanke.com/t/30991
题意
一个n*m的方格矩阵,有的格子被涂成了黑色,问该矩阵中有多少个子矩阵,子矩阵不包含黑色格子。
分析
参考https://blog.csdn.net/Sirius_han/article/details/82313029
n=1e5,m=100。首先思考一下没有黑点的话,子矩阵总数怎么算。
现有长为L的大矩阵,对于固定高度h,其子矩阵的个数是这样计算的
for(int i=; i<=L; i++){
for(int j=i; j>; j--){
count+=h;
}
}
那么对于不同高度,只需要再加一维循环就好。
解决有黑点的问题,当存在黑点时
先看高为H(4)的子矩阵个数:以(4, 7)为右下角的高为H的子矩阵个数为3个,由L=4处再向左,就只能构成高为2的子矩阵了;
那么怎么该上边的代码才能得出答案呢?如下:
for(int i=; i<=H; i++){
for(int j=; j<=L; j++){
h=i;
for(int k=j; k>; k--){
h=min(h, i-p[k]);
count+=h;
}
}
}
//p[k]表示第k列中在i行上边的第一个黑点的位置,
那么维护p数组就是这题的重点了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int b[][], up[];
int main(){
int T, cas=;
scanf("%d", &T);
while(T--){
int n, m, K;
scanf("%d%d%d", &n, &m, &K);
for(int i=; i<=n; i++){
for(int j=; j<=m; j++){
b[i][j]=;
up[j]=;
}
}
for(int i=; i<K; i++){
int x, y;
scanf("%d%d", &x, &y);
b[x][y]=;
}
ll ans=;
for(int i=; i<=n; i++){
for(int j=; j<=m; j++){
if(b[i][j]){
up[j]=i;
}
}
for(int j=; j<=m; j++){
ll minn=0x7f7f7f7f7f7f7f7f;
for(int k=j; k>; k--){
minn=min(minn, (ll)(i-up[k]));
ans+=minn;
}
}
}
printf("Case #%d: %lld\n", ++cas, ans);
}
return ;
}
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int b[100010][110], up[110];
- int main(){
- int T, cas=0;
- scanf("%d", &T);
- while(T--){
- int n, m, K;
- scanf("%d%d%d", &n, &m, &K);
- for(int i=0; i<=n; i++){
- for(int j=0; j<=m; j++){
- b[i][j]=0;
- up[j]=0;
- }
- }
- for(int i=0; i<K; i++){
- int x, y;
- scanf("%d%d", &x, &y);
- b[x][y]=1;
- }
- ll ans=0;
- for(int i=1; i<=n; i++){
- for(int j=1; j<=m; j++){
- if(b[i][j]){
- up[j]=i;
- }
- }
- for(int j=1; j<=m; j++){
- ll minn=0x7f7f7f7f7f7f7f7f;
- for(int k=j; k>0; k--){
- minn=min(minn, (ll)(i-up[k]));
- ans+=minn;
- }
- }
- }
- printf("Case #%d: %lld\n", ++cas, ans);
- }
- return 0;
- }
ACM-ICPC 2018 南京赛区网络预赛 B The writing on the wall(思维)的更多相关文章
- 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 ...
- 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 ...
随机推荐
- NEXUS 上传到私仓的SNAPSHOT 包下载不下来
使用NEXUS 上传 SNAPSHOT版本的jar包到服务器上,但是下载不下来,报错提示:Dependency ... not found 后来百度到一句话: Maven内置的插件远程仓库配置,关闭了 ...
- IDEA修改module的名字
首先右键module名,选择[Refactor]-[Rename...] 然后选择[Rename module] 只修改这些对于当前开发是没有问题了 但是刚开始把module添加成maven项目的时候 ...
- C# 获取变量或对象的栈与堆地址
C# 获取变量或对象的栈与堆地址 来源 https://www.cnblogs.com/xiaoyaodijun/p/6605070.html using System; using System.C ...
- nswl 收集日志
nswl 收集日志 参考链接:https://docs.citrix.com/en-us/citrix-adc/12-1/system/web-server-logging.html PS C:\Us ...
- Awesome-3d
1.素描-你的3D内容在网络,移动,AR,和虚拟现实. 2.跨平台AR SDK =======================
- PHP 事务写法
$md=new Model(); //创建事务 $md->startTrans(); //开始事务 $md->table("ym_xxx")->where(&qu ...
- MT【270】含参绝对值函数最大之二
已知$f(x)=2ax\cos^2x+(a-1)\cos x-1,a>0$,记$|f(x)|$的最大值为$A$,1)求A.2)证明:$|-2a\sin 2x+(1-a)\sin x|\le 2A ...
- 用keras实现基本的回归问题
数据集介绍 共有506个样本,拆分为404个训练样本和102个测试样本 该数据集包含 13 个不同的特征: 人均犯罪率. 占地面积超过 25000 平方英尺的住宅用地所占的比例. 非零售商业用地所占的 ...
- sshd启动报错Could not load host key
~ # /usr/sbin/sshd Could not load host key: /etc/ssh/ssh_host_rsa_key Could not load host key: /etc/ ...
- bzoj3829 POI2014 FAR-FarmCraft
题目链接 思路 用\(f[i]\)表示完成第\(i\)棵子树所需要得时间. 考虑如果有两个子树\(a\)和\(b\),如果先去完成子树\(a\),那么对于花费得时间就是\(f[b] + siz[a] ...