「codechefGRID」Sherlock and the Grid
这个纯模拟吧
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<set> #define ll long long using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int T,n; char mp[1005][1005]; bool mark[1005][1005]; void solve() { int ans=0; memset(mark,0,sizeof(mark)); for(int i=1;i<=n;i++) { bool f=0,g=0; for(int j=n;j;j--) { if(mp[i][j]=='#')f=1; mark[i][j]|=f; } for(int j=n;j;j--) { if(mp[j][i]=='#')g=1; mark[j][i]|=g; } } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(!mark[i][j])ans++; printf("%d\n",ans); } int main() { T=read(); while(T--) { n=read(); for(int i=1;i<=n;i++) scanf("%s",mp[i]+1); solve(); } return 0; } |
Subscribe