codeforces480E Parking Lot

來源:互聯網
上載者:User

標籤:

題目大意:給一個點陣,其中有的地方沒有點,操作是去掉某個點,並詢問當前點陣中最大的正方形

若沒有修改的話,裸dp

加上修改,可以考慮時光倒流,這樣答案就是遞增的

可以用並查集維護點的連通性,O^2的

#include<bits/stdc++.h>using namespace std;#define maxn 2010inline 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-1);    r[x].f[y]=r[x].find(y+1);}int main(){    scanf("%d%d%d",&n,&m,&q);    for(int i=1;i<=n;++i)        for(int j=1;j<=m+1;++j){            l[i].f[j]=j;            r[i].f[j]=j;            u[i][j]=i;        }    for(int i=1;i<=n;++i)scanf("%s",s[i]+1);    for(int i=1;i<=q;++i)scanf("%d%d",&qx[i],&qy[i]),s[qx[i]][qy[i]]=‘X‘;    for(int i=1;i<=n;++i)        for(int j=1;j<=m;++j)            if(s[i][j]==‘.‘)                del(i,j);    for(int i=1;i<=n;++i)        for(int j=1;j<=m;++j)            if(s[i][j]==‘.‘){                u[i][j]=u[i-1][j];                f[i][j]=min(f[i-1][j-1]+1,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=1;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]-1;i>=1;--i)MIN(lg[i],lg[i+1]),MIN(rg[i],rg[i+1]);        for(int i=qx[v]+1;i<=n;++i)MIN(lg[i],lg[i-1]),MIN(rg[i],rg[i-1]);        for(int i=1;i<=qx[v];++i)            while(i+sz<=n&&min(rg[i],rg[i+sz])+min(lg[i],lg[i+sz])-1>sz)                ++sz;    }    for(int i=1;i<=q;++i)        printf("%d\n",ans[i]);    return 0;}
View Code

 

codeforces480E Parking Lot

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.