zoukankan      html  css  js  c++  java
  • Football Foundation (FOFO) TOJ 2556

    The football foundation (FOFO) has been researching on soccer; they created a set of sensors to describe the ball behavior based on a grid uniformly distributed on the field. They found that they could predict the ball movements based on historical analysis. Each square sensor of the grid can detect the following patterns:

     

    N  north (up the field) S  south (south the field) E  east (to the right on the field) W  west (to the left on the field)

    For example, in grid 1, suppose the ball was thrown into the field from north side into the field. The path the sensors detected for this movement follows as shown. The ball went through 10 sensors before leaving the field.

    Comparing with what happened on grid 2, the ball went through 3 sensors only once, and started a loop through 8 instructions and never exits the field.

    You are selected to write a program in order to evaluate line judges job, with the following out put based on each grid of sensors, the program needs to determine how long it takes to the ball to get out of the grid or how the ball loops around.

     

    Input

    There will be one or more grids of sensors for the same game. The data for each is in the following form. On the first line are three integers separated by blanks: The number of rows in the grid, the number of columns in the grid, and the number of the column in which the ball enters from the north. The grid column's number starts with one at the left. Then come the rows of direction instructions. The lines of instructions contain only the characters N, S, E or W, with no blanks. The end of input is indicated by a grid containing 0 0 0 as limits.

     

    Output

    For each grid in the input there is one line of output. Either the ball follows a certain number of sensors and exits the field on any one of the four sides or else the ball follows the behavior on some number of sensors repeatedly. The sample input below corresponds to the two grids above and illustrates the two forms of output. The word "step" is always immediately followed by "(s)" whether or not the number before is 1.

     

    Sample Input

    3 6 5
    NEESWE
    WWWESS
    SNWWWW
    4 5 1
    SESWE
    EESNW
    NWEEN
    EWSEN
    0 0 0
    

     

    Sample Output

    10 step(s) to exit
    3 step(s) before a loop of 8 step(s)
    #include <iostream> 
    using namespace std;
    
    int main()
    {
            int row, col, num;
        while (cin>>row>>col>>num)//&&(row!=0&&col!=0) 
        {
            if(row==0||col==0||num==0)
                break;
            char array[100][100];
            int s[100][100]={0};//初始化 
            for(int i = 0;i < row; i++)
            {
                for(int j = 0; j < col; j++)
                cin >> array[i][j];
            }
         
                int m = 0;
                s[m][num-1]=1;
                int k = 2*col*row;//为了防止无限制循环下去 
                while(k--)
                {        
                switch (array[m][num-1])
                {
                    case 'N' :
                        {
                            if (m!=0)
                            {
                               m--;
                               s[m][num-1] = s[m][num-1]+1;
                               
                            }
                       
                            break;
                            }
                    case 'S' :
                        {
                            if (m!=(row-1))
                            {
                                m++;
                                s[m][num-1] = s[m][num-1]+1;
                                
                            }
                        
                            break;
                        }
                    case 'W' :
                        {
                            if ((num-1)!=0)
                            {
                                num--;
                                s[m][num-1] = s[m][num-1]+1;
                                
                            }
                          
                            break; 
                        }
                     case 'E' : 
                        {
                            if ((num-1)!=(col-1))
                            {
                                num++;
                                s[m][num-1] = s[m][num-1]+1;
                                
                            }
                        
                             break;
                        }
                    }
                }
                int c=0,d=0;
                for(int i = 0;i<row;i++)
                {
                
                    for (int j = 0;j <col;j++)
                    {
                        if(s[i][j]==1)
                        c++;
                        else if(s[i][j]>1)
                        d++;
                    }
                 } 
                if(d==0)
                cout << c << " step(s) to exit" << endl; 
                else
                cout << c << " step(s) before a loop of " << d << " step(s)"<< endl;
                }
           return 0;    
    }
  • 相关阅读:
    固定思维的可怕(转)
    Javascript模块化编程:require.js的用法
    js中将字符串转为JSON的三种方式
    cf 55D 数位dp 好题
    fzu 2113 数位dp
    uestc 250 数位dp(水)
    hdu 3652数位dp
    数位dp 3943 二分法
    hdu 3943 经典数位dp好题
    hdu 4871 树的分治+最短路记录路径
  • 原文地址:https://www.cnblogs.com/wft1990/p/6163327.html
Copyright © 2011-2022 走看看