codeforces480E Parking Lot
题目大意:给一个点阵,其中有的地方没有点,操作是去掉某个点,并询问当前点阵中最大的正方形
若没有修改的话,裸dp
加上修改,可以考虑时光倒流,这样答案就是递增的
可以用并查集维护点的连通性,O^2的
- #include<bits/stdc++.h>
- using namespace std;
- #define maxn 2010
- inline void MIN(int &a,int b){if(a>b)a=b;}
- inline void MAX(int &a,int b){if(a<b)a=b;}
- int n,m,q,sz;
- int f[maxn][maxn],u[maxn][maxn],lg[maxn],rg[maxn],qx[maxn],qy[maxn],ans[maxn];
- char s[maxn][maxn];
- struct line{
- int f[maxn];
- int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
- }l[maxn],r[maxn];
- void del(int x,int y){
- l[x].f[y]=l[x].find(y-);
- r[x].f[y]=r[x].find(y+);
- }
- int main(){
- scanf("%d%d%d",&n,&m,&q);
- for(int i=;i<=n;++i)
- for(int j=;j<=m+;++j){
- l[i].f[j]=j;
- r[i].f[j]=j;
- u[i][j]=i;
- }
- for(int i=;i<=n;++i)scanf("%s",s[i]+);
- for(int i=;i<=q;++i)scanf("%d%d",&qx[i],&qy[i]),s[qx[i]][qy[i]]='X';
- for(int i=;i<=n;++i)
- for(int j=;j<=m;++j)
- if(s[i][j]=='.')
- del(i,j);
- for(int i=;i<=n;++i)
- for(int j=;j<=m;++j)
- if(s[i][j]=='.'){
- u[i][j]=u[i-][j];
- f[i][j]=min(f[i-][j-]+,min(i-u[i][j],j-l[i].find(j)));
- MAX(sz,f[i][j]);
- }
- for(int v=q;v;--v){
- ans[v]=sz;
- del(qx[v],qy[v]);
- for(int i=;i<=n;++i){
- lg[i]=qy[v]-l[i].find(qy[v]);
- rg[i]=r[i].find(qy[v])-qy[v];
- }
- for(int i=qx[v]-;i>=;--i)MIN(lg[i],lg[i+]),MIN(rg[i],rg[i+]);
- for(int i=qx[v]+;i<=n;++i)MIN(lg[i],lg[i-]),MIN(rg[i],rg[i-]);
- for(int i=;i<=qx[v];++i)
- while(i+sz<=n&&min(rg[i],rg[i+sz])+min(lg[i],lg[i+sz])->sz)
- ++sz;
- }
- for(int i=;i<=q;++i)
- printf("%d\n",ans[i]);
- return ;
- }
codeforces480E Parking Lot的更多相关文章
- [LintCode] Parking Lot 停车场问题
Design a parking lot. see CC150 OO Design for details.1) n levels, each level has m rows of spots an ...
- [CareerCup] 8.4 Parking Lot 停车场问题
8.4 Design a parking lot using object-oriented principles. LintCode上的原题,请参见我的另一篇博客Parking Lot 停车场问题. ...
- Codeforces 46D Parking Lot
传送门 D. Parking Lot time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #135 (Div. 2) E. Parking Lot 线段数区间合并
E. Parking Lot time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Amazon Interview Question: Design an OO parking lot
Design an OO parking lot. What classes and functions will it have. It should say, full, empty and al ...
- HDOJ(HDU) 1673 Optimal Parking
Problem Description When shopping on Long Street, Michael usually parks his car at some random locat ...
- Lesson 28 No parking
Text Jasper White is one of those rare people who believes in ancient myths. He has just bought a ne ...
- [PA2014]Parking
[PA2014]Parking 题目大意: 停车场是一个宽度为\(w(w\le10^9)\)的矩形.我们以其左下角顶点为原点,坐标轴平行于矩形的边,建立直角坐标系.停车场很长,我们可以认为它一直向右边 ...
- Codeforces 219E Parking Lot 线段树
Parking Lot 线段树区间合并一下, 求当前要占的位置, 不包括两端点的写起来方便一点. #include<bits/stdc++.h> #define LL long long ...
随机推荐
- PHP之数据类型
1.PHP字符串(String):一个字符串是一串字符的序列,就像"Hello world!":可以将任何文本放在单引号和双引号中: <?php $x="Hello ...
- C#性能测试方法
用 System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); for (int i ...
- soapui中文操作手册(七)----Web Service Sample Project
REST推理 这份简短的教程将引导您完成架构推断功能. 我们将创建一个新的项目,并添加一个REST服务,而初始WADL文件启动了. 发送请求后,我们就可以使用响应来构建我们的架构. 演示请求 为了演示 ...
- HDU 3090 (贪心)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3090 题目大意:一共n段路.每段路每千米都会被抢劫一定数量,可以雇佣武士护卫m千米.问最少被抢劫数量 ...
- weblogic应用平台常见问题小结
http://blog.sina.com.cn/s/blog_4aa08b7c010004yc.html 1.当以另一用户登录系统后,系统却显示的是前一用户的身份. 这是由于页面信息没有刷新造成 ...
- Codeforces Round #249 (Div. 2) A - Queue on Bus Stop
水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...
- Visiual Studio2012 CLR20r3问题
看到有更新,习惯性的点了,升级到Visiual Studio Ultimate 2012 Update 1,并且按照提升重启了电脑.因为昨天太晚,也没验证.尽早打开VS,结果直接Crash.错误如下: ...
- BestCoder Round #77
T1 xiaoxin juju needs help 计算组合数然后多重集排列乱搞,注意判无解情况(TM我就判错然后FST了). #include<cstdio> #include< ...
- 彩色照片转换为黑白照片(Color image converted to black and white picture)
This blog will be talking about the color image converted to black and white picture. The project st ...
- qt编译常见错误
一.fatal error: QWidget: 没有那个文件或目录 类似于找不到文件目录的,在.pro文件中添加 QT +=\ widgets 类似就可以编译通过