CF 480 E. Parking Lot
CF 480 E. Parking Lot
http://codeforces.com/contest/480/problem/E
题意:
给一个n*m的01矩阵,每次可以将一个0修改为1,求最大全0的矩阵。
分析:
将询问离线,从后往前处理询问,相当于每次将一个1变成0,答案是递增的。
用悬线法或者单调栈来求。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cctype>
#include<set>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ; char a[N][N];
int x[N], y[N], L[N], R[N], U[N][N], D[N][N], q1[N], q2[N], ans[N], sk[N];
int Ans, n, m; void solve() {
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j)
U[i][j] = a[i][j] == '.' ? U[i-][j] + : ;
for (int i=n; i>=; --i)
for (int j=; j<=m; ++j)
D[i][j] = a[i][j] == '.' ? D[i+][j] + : ;
for (int i=; i<=n; ++i) { // 单调栈
U[i][] = U[i][m+] = -;
for (int top=,j=; j<=m+; ++j) {
while (top > && U[i][j] < U[i][sk[top]]) R[sk[top]] = j, top--;
sk[++top] = j;
}
for (int top=,j=m; j>=; --j) {
while (top > && U[i][j] < U[i][sk[top]]) L[sk[top]] = j, top --;
sk[++top] = j;
}
for (int j=; j<=m; ++j)
Ans = max(Ans, min(U[i][j], R[j] - L[j] - ));
}
/*memset(R, 0x3f, sizeof(R)); // 悬线法
for (int i=1; i<=n; ++i) {
int last = 0;
for (int j=1; j<=m; ++j) {
if (a[i][j] == '.') L[j] = max(L[j], last + 1);
else last = j, L[j] = 0;
}
last = m + 1;
for (int j=m; j>=1; --j) {
if (a[i][j] == '.') R[j] = min(R[j], last - 1);
else last = j, R[j] = m + 1;
}
for (int j=1; j<=m; ++j)
Ans = max(Ans, min(U[i][j], R[j] - L[j] + 1));
}*/
}
bool update(int x,int k) { // 判断能否组成k*k的方阵
int L1 = , R1 = , L2 = , R2 = ;
for (int j=; j<=m; ++j) {
while (L1 <= R1 && j - q1[L1] + > k) L1 ++;
while (L1 <= R1 && U[x][q1[R1]] >= U[x][j]) R1 --;
q1[++R1] = j; while (L2 <= R2 && j - q2[L2] + > k) L2 ++;
while (L2 <= R2 && D[x][q2[R2]] >= D[x][j]) R2 --;
q2[++R2] = j; if (j >= k && U[x][q1[L1]] + D[x][q2[L2]] - >= k) {
Ans = k;
return true;
}
}
return false;
}
void Change(int x,int y) {
a[x][y] = '.';
for (int i=x; i<=n; ++i) U[i][y] = a[i][y] == '.' ? U[i-][y] + : ;
for (int i=x; i>=; --i) D[i][y] = a[i][y] == '.' ? D[i+][y] + : ;
}
int main() {
n = read(), m = read(); int Q = read();
for (int i=; i<=n; ++i) scanf("%s",a[i]+);
for (int i=; i<=Q; ++i) {
x[i] = read(),y[i] = read();
a[x[i]][y[i]] = 'X';
}
solve();
for (int i=Q; i>=; --i) {
ans[i] = Ans;
Change(x[i], y[i]);
while (update(x[i], Ans + ));
}
for (int i=; i<=Q; ++i) printf("%d\n",ans[i]);
return ;
}
CF 480 E. Parking Lot的更多相关文章
- Codeforces 480.E Parking Lot
E. Parking Lot time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...
- 【26.8%】【CF 46D】Parking Lot
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- CF 480 B Long Jumps (map标记)
题目链接:http://codeforces.com/contest/480/problem/B 题目描述: Long Jumps Valery is a PE teacher at a ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
随机推荐
- BZOJ4887:[TJOI2017]可乐(矩阵乘法)
Description 加里敦星球的人们特别喜欢喝可乐.因而,他们的敌对星球研发出了一个可乐机器人,并且 放在了加里敦星球的1号城市上.这个可乐机器人有三种行为:停在原地,去下一个相邻的 城市,自爆. ...
- .net mvc 路由
Asp.net Mvc之Action如何传多个参数 在Global.asax文件中,默认路由如下. routes.MapRoute( "Default", // 路由名称 &quo ...
- js 构造函数创建钟表
翻出来之前的一些效果,觉得这个时钟还挺好玩的就写出来共大家分享: HTML代码如下: <div id="box"> </div> 当前盒子用于插入钟表内容: ...
- 用python实现ping
#!/usr/bin/env python #coding=utf-8 import os import argparse import socket import struct import sel ...
- vue使用element案列
第一步:使用vue创建项目‘ 第二步:在项目添加element cmd:vue add element demo:https://github.com/weibanggang/vuemode.git
- 前端面试题(copy)
前端开发面试知识点大纲: HTML&CSS: 对Web标准的理解.浏览器内核差异.兼容性.hack.CSS基本功:布局.盒子模型.选择器优先级及使用.HTML5.CSS3.移动端适应. Jav ...
- vector 定义的二维数组的遍历
之前我们分享了STL的一些容器,再介绍vector中只介绍了二维的vector的定义并没有说二维的vector怎么遍历,那么我们今天就来看下二维的vector怎么遍历 看下面的代码吧. #includ ...
- 19-3-6Python中字典的解释、使用、嵌套
一.字典 为什么学字典: 列表的缺点: 1.列表如果存储的数据比较多,那么他的查询速度相对慢. 2.列表存储的数据关联性不强. 字典是什么: Python基础数据类型之一:字典. Python中唯一的 ...
- md5加密+盐方式一
这种方法是采用随机生成盐值加入password中组合成的新密码,下面是md5+盐的一个工具类,直接导入使用即可! 工具类 package com.oracle.utils; import java.s ...
- laravel form 表单提交
form表单需要加token,不然会出现419错误,csrf_token不用自己生成,放进去就行,laravel自己会生成 路由: 控制器生成一个: