时间限制: 1 Sec 内存限制: 256 MB
题面谢绝公开。
大模拟需要题解么??
#include<bits/stdc++.h> #define rint register int using namespace std; int T,len,vis[1111][1111],ans; int l;//l表示长边在哪个方向,1表南北,2表东西,0表底面在下。 int x,y;//左下角在网格中占据的坐标 int h;//高度 char ch[103]; inline int Max(int A,int B){return A>B?A:B;} inline void North(){if(l==0){y+=1;l=1;}else if(l==1){y+=h;l=0;}else y+=1;} inline void South(){if(l==0){y-=h;l=1;}else if(l==1){y-=1;l=0;}else y-=1;} inline void East(){if(l==0){x+=1;l=2;}else if(l==1)x+=1;else{x+=h;l=0;}} inline void West(){if(l==0){x-=h;l=2;}else if(l==1)x-=1;else{x-=1;l=0;}} int main() { // freopen("ex_block2.in","r",stdin); // freopen("my.out","w",stdout); scanf("%d",&T); while(T--) { l=x=y=len=ans=0; memset(vis,0,sizeof(vis)); scanf("%d %s",&h,ch+1); len=strlen(ch+1);vis[555][555]=1; for(rint i=1;i<=len;++i) { switch(ch[i]) { case ‘N‘:{North();break;} case ‘S‘:{South();break;} case ‘E‘:{East(); break;} case ‘W‘:{West(); break;} } if(l==0) { vis[x+555][y+555]++; ans=Max(ans,vis[x+555][y+555]); } else if(l==1) { for(rint i=0;i<h;++i) { vis[x+555][y+i+555]++; ans=Max(ans,vis[x+555][y+i+555]); } } else { for(rint i=0;i<h;++i) { vis[x+i+555][y+555]++; ans=Max(ans,vis[x+i+555][y+555]); } } } if(l==0) printf("%d\n%d\n%d\n",x,y,ans); else if(l==1) { for(rint i=0;i<h;++i)printf("%d ",x);puts(""); for(rint i=0;i<h;++i)printf("%d ",y+i);puts(""); printf("%d\n",ans); } else { for(rint i=0;i<h;++i)printf("%d ",x+i);puts(""); for(rint i=0;i<h;++i)printf("%d ",y);puts(""); printf("%d\n",ans); } } return 0; }
原文:https://www.cnblogs.com/xingmi-weiyouni/p/11626416.html