[暴力]JZOJ 5886 军训
分析
这题显然任意一个矩形的三个角都有#号而另外一个没有就不可行
我们定义left[i][j]为(i,j)往左第一个为#号的列,up[i][j]类似
然后像邻接表一样乱搞一下就好
#include <iostream> #include <cstdio> #include <memory.h> using namespace std; const int N=2e3+10; int t,n,m; int l[N][N],u[N][N]; bool b[N],p[N],q[N]; char c[N][N]; int main() { freopen("rect.in","r",stdin); freopen("rect.out","w",stdout); scanf("%d",&t); while (t--) { memset(b,0,sizeof b); memset(p,0,sizeof p); memset(l,0,sizeof l); memset(u,0,sizeof u); int i; scanf("%d%d",&n,&m); for (i=1;i<=n;i++) for (int j=1;j<=m;j++) { do { scanf("%c",&c[i][j]); } while (c[i][j]!='.'&&c[i][j]!='#'); if (c[i][j]=='#') b[i]=1; if (c[i][j-1]=='#') l[i][j]=j-1; else l[i][j]=l[i][j-1]; if (c[i-1][j]=='#') u[i][j]=i-1; else u[i][j]=u[i-1][j]; } for (i=1;i<=n;i++) if (b[i]) { int y=c[i][m]=='#'?m:l[i][m]; int x=u[i][y]; for (int j=l[i][y];j;j=l[i][j]) { if (u[i][j]!=x) goto print; } } print:; if (i==n+1) printf("Yes\n"); else printf("No\n"); } fclose(stdin);fclose(stdout); }
在日渐沉没的世界里,我发现了你。