Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

麻烦问下 我这个程序在浙大上AC Mid Central Regionals上找的数据也对 请问是加数据了么?能给贴下么?谢谢

Posted by CTcoolL at 2008-04-18 10:53:08 on Problem 1573 and last updated at 2008-04-18 10:53:33
#include<iostream>
using namespace std;
char a[11][11];
int s[11][11];
struct node{
       int x,y;
};
int counter = 0;
node transform(node temp){
     int x = temp.x,y = temp.y;
     if(a[x][y]=='N') {
                      temp.x = x-1;
     }
     else if(a[x][y]=='W') {
                      temp.y = y-1;
     }
     else if(a[x][y]=='S') {
          temp.x = x+1;
     }
     else {
          temp.y = y+1;
     }
     s[x][y] = counter;
     return temp;
}          
int main(){
    int m,n,begin;
    while(cin>>n>>m>>begin&&n!=0&&m!=0&&begin!=0){
          counter = 0;
          memset(s,-1,sizeof(s));
          for(int i = 0;i<n;i++){
                  for(int j = 0;j<m;j++){
                          cin>>a[i][j];
                  }
          }
          node temp;
          temp.x = 0;
          temp.y = begin-1;
          s[temp.x][temp.y] = 0;
          while(1){
              counter++;     
              temp = transform(temp);
              if(temp.x<0||temp.x>=n||temp.y<0||temp.y>=m){
                          cout<<counter<<" step(s) to exit\n";
                          break;
              }                                 
              if(s[temp.x][temp.y]>=0){
                          cout<<s[temp.x][temp.y]-1<<" step(s) before a loop of ";
                          int max = -1;
                          if(s[temp.x][temp.y-1]>=0&&s[temp.x][temp.y-1]>max){
                                   max = s[temp.x][temp.y-1];
                          }
                          if(s[temp.x][temp.y+1]>=0&&s[temp.x][temp.y+1]>max){
                                   max = s[temp.x][temp.y+1];
                          }
                          if(s[temp.x-1][temp.y]>=0&&s[temp.x-1][temp.y]>max){
                                   max = s[temp.x-1][temp.y];
                          }
                          if(s[temp.x+1][temp.y]>=0&&s[temp.x+1][temp.y]>max){
                                   max = s[temp.x+1][temp.y];
                          }
                          cout<<max-s[temp.x][temp.y]+1<<" step(s)\n";
                          break;
              }
              
          }
    }
}                                                                                                                                               

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator