1 条题解
-
0
自动搬运
来自洛谷,原作者为

iyaang
不因过往而自卑搬运于
2025-08-24 22:48:23,当前版本为作者最后更新于2023-07-12 21:04:47,作者可能在搬运后再次修改,您可在原文处查看最新版自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多
以下是正文
首先找出必须是
.和#的位置,剩下的就可以随便填,最少分子就是都填.,最多分子就是都填#。根据题意,对于给定的任意 ,它们都位于边界上,必定是
#;同时只要其所对应的 合法,则 必定为.,于是我们就得到了边界限制下的最初答案。接下来考虑不在边界上的 ,对于任意的 ,要么 为
.,要么 和 都为#。首先可以通过边界上的 根据后者条件选定出剩下的#,对于剩下的还没有被钦定的位置再进行下面的筛选:如果任意的 , 都不合法,此时有没有别的位置会使其成为#,那么这个位置只能成为.。最后我们再将后者条件反过来考虑,如果 为.且 还未被钦定,此时其他条件都已经用完了,那么 只能为.了。至此,题目里面提供的信息都已经用上,仍没有被遍历的节点就可以随便填了。可以发现,上面的两次扩散过程都可以轻松的用 bfs 来实现,于是复杂度 。本人代码为了图省事两次 bfs 缩在一起了,看起来可能有点抽象。
#include<bits/stdc++.h> #define ld long double #define ui unsigned int #define ull unsigned long long #define int long long #define eb emplace_back #define pb pop_back #define ins insert #define mp make_pair #define pii pair<int,int> #define fi first #define se second #define power(x) ((x)*(x)) #define gcd(x,y) (__gcd((x),(y))) #define lcm(x,y) ((x)*(y)/gcd((x),(y))) #define lg(x,y) (__lg((x),(y))) using namespace std; namespace FastIO { template<typename T=int> inline T read() { T s=0,w=1; char c=getchar(); while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();} while(isdigit(c)) s=(s*10)+(c^48),c=getchar(); return s*w; } template<typename T> inline void read(T &s) { s=0; int w=1; char c=getchar(); while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();} while(isdigit(c)) s=(s*10)+(c^48),c=getchar(); s=s*w; } template<typename T,typename... Args> inline void read(T &x,Args &...args) { read(x),read(args...); } template<typename T> inline void write(T x,char ch) { if(x<0) x=-x,putchar('-'); static char stk[25]; int top=0; do {stk[top++]=x%10+'0',x/=10;} while(x); while(top) putchar(stk[--top]); putchar(ch); return; } } using namespace FastIO; namespace MTool { #define TA template<typename T,typename... Args> #define TT template<typename T> static const int Mod=1e9+7; TT inline void Swp(T &a,T &b) {T t=a;a=b;b=t;} TT inline void cmax(T &a,T b) {a=max(a,b);} TT inline void cmin(T &a,T b) {a=min(a,b);} TT inline void Madd(T &a,T b) {a=a+b>Mod?a+b-Mod:a+b;} TT inline void Mdel(T &a,T b) {a=a-b<0?a-b+Mod:a-b;} TT inline void Mmul(T &a,T b) {a=a*b%Mod;} TT inline void Mmod(T &a) {a=(a%Mod+Mod)%Mod;} TT inline T Cadd(T a,T b) {return a+b>=Mod?a+b-Mod:a+b;} TT inline T Cdel(T a,T b) {return a-b<0?a-b+Mod:a-b;} TT inline T Cmul(T a,T b) {return a*b%Mod;} TT inline T Cmod(T a) {return (a%Mod+Mod)%Mod;} TA inline void Madd(T &a,T b,Args... args) {Madd(a,Cadd(b,args...));} TA inline void Mdel(T &a,T b,Args... args) {Mdel(a,Cadd(b,args...));} TA inline void Mmul(T &a,T b,Args... args) {Mmul(a,Cmul(b,args...));} TA inline T Cadd(T a,T b,Args... args) {return Cadd(Cadd(a,b),args...);} TA inline T Cdel(T a,T b,Args... args) {return Cdel(Cdel(a,b),args...);} TA inline T Cmul(T a,T b,Args... args) {return Cmul(Cmul(a,b),args...);} TT inline T qpow(T a,T b) {int res=1; while(b) {if(b&1) Mmul(res,a); Mmul(a,a); b>>=1;} return res;} TT inline T qmul(T a,T b) {int res=0; while(b) {if(b&1) Madd(res,a); Madd(a,a); b>>=1;} return res;} TT inline T spow(T a,T b) {int res=1; while(b) {if(b&1) res=qmul(res,a); a=qmul(a,a); b>>=1;} return res;} TT inline void exgcd(T A,T B,T &X,T &Y) {if(!B) return X=1,Y=0,void(); exgcd(B,A%B,Y,X),Y-=X*(A/B);} TT inline T Ginv(T x) {T A=0,B=0; exgcd(x,Mod,A,B); return Cmod(A);} #undef TT #undef TA } using namespace MTool; inline void file() { freopen(".in","r",stdin); freopen(".out","w",stdout); return; } bool Mbe; namespace LgxTpre { static const int MAX=1010; static const int bMAX=11; static const int inf=2147483647; static const int INF=4557430888798830399; static const int mod=1e9+7; static const int bas=131; int n,m,T; int wx[bMAX],wy[bMAX],x,y,all; int ans[MAX][MAX],vis[MAX][MAX][bMAX]; queue<pii> q; inline void lmy_forever() { auto check=[&](int x,int y)->bool { return x>=1&&x<=n&&y>=1&&y<=m; }; read(n,m,T),memset(ans,-1,sizeof ans); for(int i=1;i<=T;++i) { read(wx[i],wy[i],all); while(all--) { read(x,y),ans[x][y]=1,vis[x][y][i]=1; if(check(x-wx[i],y-wy[i])) ans[x-wx[i]][y-wy[i]]=0; } } auto bfs=[&](int res)->void { for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) if(ans[i][j]==res) q.emplace(mp(i,j)); while(!q.empty()) { auto now=q.front(); q.pop(); for(int i=1;i<=T;++i) { int tx=now.fi+(res?-1:1)*wx[i],ty=now.se+(res?-1:1)*wy[i]; if(check(tx,ty)&&ans[tx][ty]==-1) ans[tx][ty]=res,q.emplace(mp(tx,ty)); } } }; bfs(1); for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) if(ans[i][j]==-1) { int flag=0; for(int k=1;k<=T;++k) flag|=(!check(i-wx[k],j-wy[k])); if(flag) ans[i][j]=0; } bfs(0); for(int i=1;i<=m;++i,puts("")) for(int j=1;j<=n;++j) putchar(ans[j][i]==1?'#':'.'); puts(""); for(int i=1;i<=m;++i,puts("")) for(int j=1;j<=n;++j) putchar(ans[j][i]==0?'.':'#'); puts(""); } } bool Med; signed main() { //file(); fprintf(stderr,"%.3lf MB\n",abs(&Med-&Mbe)/1048576.0); int Tbe=clock(); LgxTpre::lmy_forever(); int Ted=clock(); cerr<<1e3*(Ted-Tbe)/CLOCKS_PER_SEC<<" ms\n"; return (0-0); }
- 1
信息
- ID
- 6100
- 时间
- 5000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者