poj1573

有段时间没做题了,最近游泳游的还可以。

犯了几个非常非常低级的错误。

cin>>n,m,p

这种写法,就是最近生疏的原因。

还有一个判断条件写反了。

还有一个错误,就是连续四个if的地方,我直接没加else,导致莫名其妙的错误。

要不这题1AC,那就酸爽。

// #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;
    }
}
时间: 2024-12-19 10:18:07

poj1573的相关文章

poj1573 Robot Motion

题目链接: http://poj.org/problem?id=1573 题目: Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10202   Accepted: 4971 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direct

POJ1573——Robot Motion

Robot Motion Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are N north (up the page) S south (down the page)

poj1573模拟

Robot Motion Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] [Discuss] Description A robot has been programmed to follow the instructions in its path. Instructions for the nex

poj1573&amp;&amp;hdu1035 Robot Motion(模拟题)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1035 POJ:   http://poj.org/problem?id=1573 Description A robot has been programmed to follow the instructions in its path. Instructions for

POJ1573 ZOJ1708 UVA10116 UVALive5334 HDU1035 Robot Motion【DFS+BFS】

Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16166 Accepted: 7643 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a g

poj1573 模拟

Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11270   Accepted: 5487 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in

POJ1573(枚举,动态规划)

Flip Game Time Limit: 1000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] [Discuss] Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 s

acm常见算法及例题

转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法

ACM算法总结及刷题参考

参考:http://bbs.byr.cn/#!article/ACM_ICPC/11777 OJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 初期: 一.基本算法: (1)枚举. (poj1753,poj2965)    (2)贪心(poj1328,poj2109,poj2586)    (3)递归和分治法.     (4)递推.     (5)构造法.(po