标签:时间 set name vector ring 莫名其妙 iostream end sse
// #includes {{{ #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<assert.h> #include<stdarg.h> #include<time.h> #include<limits.h> #include<ctype.h> #include<string> #include<map> #include<set> #include<queue> #include<algorithm> #include<vector> #include<iostream> #include<sstream> using namespace std; // }}} // #defines {{{ #define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define REP(i,n) for(int i=0;i<(n);i++) #define REP1(i,a,b) for(int i=(a);i<=(b);i++) #define PER(i,n) for(int i=(n)-1;i>=0;i--) #define PER1(i,a,b) for(int i=(a);i>=(b);i--) #define RI(x) scanf("%d",&x) #define DRI(x) int x;RI(x) #define RII(x,y) scanf("%d%d",&x,&y) #define DRII(x,y) int x,y;RII(x,y) #define RIII(x,y,z) scanf("%d%d%d",&x,&y,&z) #define DRIII(x,y,z) int x,y,z;RIII(x,y,z) #define RS(x) scanf("%s",x) #define PI(x) printf("%d\n",x) #define PIS(x) printf("%d ",x) #define CASET int ___T,cas=1;scanf("%d",&___T);while(___T--) #define CASEN0(n) int cas=1;while(scanf("%d",&n)!=EOF&&n) #define CASEN(n) int cas=1;while(scanf("%d",&n)!=EOF) #define MP make_pair #define PB push_back #define MS0(x) memset(x,0,sizeof(x)) #define MS1(x) memset(x,-1,sizeof(x)) #define F first #define S second typedef pair<int,int> PII; typedef long long LL; typedef unsigned long long ULL; // }}} const int N=20; int n,m,p; string a[N]; int f[N][N]; main(){ cin>>n>>m>>p; while ((n+m+p)!=0) { for (int i=0;i<n;i++){ cin>>a[i]; //cout<<a[i]<<endl; } for(int i=0;i<n;i++) for(int j=0;j<m;j++) f[i][j]=-1; int ni=0,nj=p-1; f[ni][nj]=1; int now=1; bool fl=true; while( fl ){ if (a[ni][nj]==‘E‘) nj++; else if (a[ni][nj]==‘N‘) ni--; else if (a[ni][nj]==‘W‘) nj--; else if (a[ni][nj]==‘S‘) ni++; if (nj>=m || nj<0 || ni<0 || ni>=n) { fl=false; cout<<now<<" step(s) to exit"<<endl; break; } //cout<<ni<<" "<<nj<<endl; //cout<<f[ni][nj]<<endl; now++; if (f[ni][nj]==-1) f[ni][nj]=now; else{ fl=false; cout<<f[ni][nj]-1<<" step(s) before a loop of "<<now-f[ni][nj]<<" step(s)"<<endl; } } cin>>n>>m>>p; } }
标签:时间 set name vector ring 莫名其妙 iostream end sse
原文地址:http://www.cnblogs.com/nisige/p/6440714.html