玄学WA0分

P1189 SEARCH

没事了,`getchar()`出的问题。
by Yuzilihhh @ 2023-11-03 21:06:55


```c #include<iostream> #include<vector> #include<cstring> using namespace std; typedef int in; in e,w;bool vis[55][55]; in hang,line;in ma[55][55];int r=1; in now[55][55]; struct node { int h; int l; }temp; vector<node>vec; char c[55][55];in n;string s; void move(in x,in y) { memset(vis,0,sizeof(vis)); int g=vec.size(); if(g==0)return ; for(int i=1;i<=g;i++) { temp=vec.front();vec.erase(vec.begin()); while(!(temp.h+x>hang||temp.h+x<=0||temp.l+y>line||temp.l+y<=0)) { if(c[temp.h+x][temp.l+y]=='X') break; if(vis[temp.h+x][temp.l+y]==1)break; int u=temp.h+x; int v=temp.l+y; vis[u][v]=1; vec.push_back(node{u,v}); temp.h=u; temp.l=v; } } return ; } int main() { cin>>hang>>line; for(in i=1;i<=hang;i++) { for(in j=1;j<=line;j++ ){ cin>>c[i][j]; if(c[i][j]=='*') { e=i;w=j; c[e][w]='.'; vis[i][j]=1; vec.push_back(node{i,j}); } } } cin>>n; for(in i=1;i<=n;i++) { cin>>s; if(s=="NORTH"){move(-1,0);} if(s=="SOUTH"){move(1,0);} if(s=="WEST"){move(0,-1);} if(s=="EAST"){move(0,1);} } for(auto i:vec) { temp.h=i.h; temp.l=i.l; c[temp.h][temp.l]='*'; } for(int i=1;i<=hang;i++) { for(int j=1;j<=line;j++) cout<<c[i][j]; cout<<endl; } return 0; } ```
by 呆呆的她啊 @ 2023-11-08 19:11:46


``` #include <bits/stdc++.h> using namespace std; struct Ans { bool f=0; int k[1001]={}; int m=0; }ans[55][55]; int r,c,n; char a[55][55]={}; string node[1001]={}; void dfs(int x,int y,int i) { if (i==n) { a[x][y]='*'; return; } if (ans[x][y].f==1) { for (int l=0;l<=ans[x][y].m;l++) { if (i==ans[x][y].k[l]) { return; } } } ans[x][y].f=1; ans[x][y].k[ans[x][y].m++]=i; int count=1; if (node[i]=="NORTH") { while (a[x-count][y]!='X'&&x-count>=0) { dfs(x-count,y,i+1); count++; } } if (node[i]=="SOUTH") { while (a[x+count][y]!='X'&&x+count<r) { dfs(x+count,y,i+1); count++; } } if (node[i]=="WEST") { while (a[x][y-count]!='X'&&y-count>=0) { dfs(x,y-count,i+1); count++; } } if (node[i]=="EAST") { while (a[x][y+count]!='X'&&y+count<c) { dfs(x,y+count,i+1); count++; } } return; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int x,y; cin >> r >> c; for (int i=0;i<r;i++) { for (int j=0;j<c;j++) { cin >> a[i][j]; if (a[i][j]=='*') { x=i; y=j; a[i][j]='.'; } } } cin >> n; for (int i=0;i<n;i++) { cin >> node[i]; } dfs(x,y,0); for (int i=0;i<r;i++) { for (int j=0;j<c;j++) { cout << a[i][j]; } cout << endl; } return 0; }
by zgcxh3022 @ 2023-11-10 12:02:43


|