五月三号训练赛
来源:互联网 发布:上海淘宝摄影实景基地 编辑:程序博客网 时间:2024/06/11 22:31
Description
Dr. Fukuoka has placed a simple robot in a two-dimensional maze. It moves within the maze and never goes out of the maze as there is no exit.
The maze is made up of H × W grid cells as depicted below. The upper side of the maze faces north. Consequently, the right, lower and left sides face east, south and west respectively. Each cell is either empty or wall and has the coordinates of (i, j) where the north-west corner has (1, 1). The row i goes up toward the south and the column j toward the east.
The robot moves on empty cells and faces north, east, south or west. It goes forward when there is an empty cell in front, and rotates 90 degrees to the right when it comes in front of a wall cell or on the edge of the maze. It cannot enter the wall cells. It stops right after moving forward by L cells.
Your mission is, given the initial position and direction of the robot and the number of steps, to write a program to calculate the final position and direction of the robot.
Input
The input is a sequence of datasets. Each dataset is formatted as follows.
H W L
c1,1c1,2...c1,W
.
.
.
cH,1cH,2...cH,W
The first line of a dataset contains three integers H, W and L (1 ≤ H, W ≤ 100, 1 ≤ L ≤ 1018).
Each of the following H lines contains exactly W characters. In the i-th line, the j-th character ci,j represents a cell at (i, j) of the maze. "." denotes an empty cell. "#" denotes a wall cell. "N", "E", "S", "W" denote a robot on an empty cell facing north, east, south and west respectively; it indicates the initial position and direction of the robot.
You can assume that there is at least one empty cell adjacent to the initial position of the robot.
The end of input is indicated by a line with three zeros. This line is not part of any dataset.
Output
For each dataset, output in a line the final row, column and direction of the robot, separated by a single space. The direction should be one of the following: "N" (north), "E" (east), "S" (south) and "W" (west).
No extra spaces or characters are allowed.
Sample Input
3 3 10E...#....5 5 19####.......#S#....#.#.##.5 5 6#.#..#....##.#.#..S.#....5 4 35..##.....##..#S....#0 0 0
Output for the Sample Input
1 3 E4 5 S4 4 E1 1 N
很像dfs,bfs,但有方向,vis[i][j][k]记录这个点的这个方向是不是走过,id[i][j][k]表示第一次走到这的步数;
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=110;int H,W,cnt;int sx,sy,sd;long long L;char grid[maxn][maxn];int vis[maxn][maxn][4],id[maxn][maxn][4];int di[][2]={{-1,0},{0,1},{1,0},{0,-1}};int DIR(char d){ if(d=='S')return 2; if(d=='W')return 3; if(d=='N')return 0; return 1;}int move(int &x,int &y,int &d){ int tx,ty; for(int i=0;i<4;i++) { tx=x+di[d][0]; ty=y+di[d][1]; if(tx<1||tx>H||ty<1||ty>W||grid[tx][ty]=='#'){d=(d+1)%4;continue;} break; } x=tx,y=ty; if(vis[x][y][d])return id[x][y][d]; vis[x][y][d]=1; id[x][y][d]=cnt++; return 0;}int main(){ //freopen("in.txt","r",stdin); while(scanf("%d%d%lld",&H,&W,&L)!=EOF,H+W+L) { for(int i=1;i<=H;i++) { scanf("%s",grid[i]+1); for(int j=1;j<=W;j++) { if(grid[i][j]=='.'||grid[i][j]=='#')continue; sx=i,sy=j; sd=DIR(grid[i][j]); } } memset(vis,0,sizeof(vis)); memset(id,0,sizeof(id)); bool flag=true; vis[sx][sy][sd]=1; id[sx][sy][sd]=1; cnt=-1; while(L) { int tv=move(sx,sy,sd); if(tv&&flag) { flag=false; L=L%(cnt-tv)+cnt-tv; } L--; } char ansd; if(sd==0)ansd='N'; else if(sd==1)ansd='E'; else if(sd==2)ansd='S'; else ansd='W'; printf("%d %d %c\n",sx,sy,ansd); } return 0;}
Description
Problem Statement
We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins. After analysis of the dictionary, we revealed they used a language that had not more than 26 letters. So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary into a computer.
How the words are ordered in the dictionary, especially whether they are ordered lexicographically, is an interesting topic to many people. As a good programmer, you are requested to write a program to judge whether we can consider the words to be sorted in a lexicographical order.
Note: In a lexicographical order, a word always precedes other words it is a prefix of. For example, ab
precedes abc
, abde
, and so on.
Input
The input consists of multiple datasets. Each dataset is formatted as follows:
nstring_1...string_n
Each dataset consists of n+1 lines. The first line of each dataset contains an integer that indicates n (1 \leq n \leq 500). The i-th line of the following n lines contains string_i, which consists of up to 10 English lowercase letters.
The end of the input is 0
, and this should not be processed.
Output
Print either yes
or no
in a line for each dataset, in the order of the input. If all words in the dataset can be considered to be ordered lexicographically, print yes
. Otherwise, print no
.
Sample Input
4cbacabba3bcaaba5abcacbbcc5abcacbcbb0
Output for the Sample Input
yesnoyesno
两个串遇到不同的标记一下,然后传闭包,在判断一下;
#include<iostream>#include<cstdio>#include<cstring>#include<string>using namespace std;int n,cnt;string a,b;int com[110][110];void solve(){ int la,lb,ax,bx; bool flag=true; cin>>a; for(int i=2;i<=n;i++) { cin>>b; if(!flag)continue; la=a.size(),lb=b.size(); ax=bx=0; while(ax<la&&bx<lb) { int p=a[ax]-'a'+1,q=b[bx]-'a'+1; if(p!=q) { com[p][q]=1; break; } ax++,bx++; } if(bx==lb&&la>lb){flag=false;} a=b; } for(int k=1;k<=30;k++) for(int i=1;i<=30;i++) for(int j=1;j<=30;j++) { if(i==j||com[i][j])continue; com[i][j]=(com[i][k]&com[k][j]); } for(int i=1;i<=30;i++) { for(int j=1;j<=30;j++) if(com[i][j]==1&&com[i][j]==com[j][i]){flag=false;break;} if(!flag)break; } if(flag)printf("yes\n"); else printf("no\n");}int main(){ //freopen("in.txt","r",stdin); while(scanf("%d",&n)!=EOF&&n) { memset(com,0,sizeof(com)); solve(); } return 0;}
- 五月三号训练赛
- 五月二号训练赛
- 洛谷五月赛
- 五月
- 五月
- 五月
- 五月
- 五月
- 七月三号
- 轨道交通三号线
- 三号伴唱※414
- 第二十三号战犯
- 一月十三号
- 三号线首个盾构区
- 高分三号卫星介绍
- 浙大五月月赛E:P-norm(输入处理)
- 五月个人赛-a problem of DP(贪心,multiset)
- 五月赛- ACMER的出行计划(分层图,dij)
- JVM学习笔记1(类加载器)
- HDU 2176(基础尼姆)从n堆石堆中取石子
- 使用CGLIB实现AOP功能核心代码
- 修改密码
- 最小表示法模板
- 五月三号训练赛
- 架构与耦合-Strust2 使用配置文件管理常量
- Springmvc构造RESTful详细讲解
- poj 1067和 hdu 1527 取石子游戏
- 一些开源产品,没事可以读读源代码
- jquery操作select小结
- 绑定类别的方法
- vmare 虚拟机安装xp错误output error file to the following location A:\GHOSTERR.TXT
- 为什么需要auto_ptr_ref