1695: 跳格子

时间限制: 1 Sec  内存限制: 128 MB
提交: 230  解决: 57
[提交][状态][讨论版]

题目描述

逸夫楼的大厅的地面有10行10列的石砖,我们用坐标(x,y)来表示石砖的位置。如图示:

一天lxl在逸夫楼大厅玩跳格子游戏,跳格子游戏有7个动作:1.向左转,2向右转,3向后转,4向左跳一格,5向前跳一格,6向右跳一格,7向后跳一格。游戏前,lxl在(1,1)处并面向y轴正方向,他会做n次动作,若某个动作会让lxl跳出逸夫楼大厅则原地不动,每一次动作后都需要你输出lxl当前的位置。当n次动作都做完后,你还需要统计lxl到达过多少个格子。

输入

第一行输入n(0<n<101),表示lxl做的动作次数,接下来有n行,每行一个整数x(0<x<8)表示要做的动作。

输出

每次动作后输出lxl的当前坐标,一共有n行。随后的第n+1行输出lxl到达过的格子总数。

样例输入

7
5
4
1
7
3
2
6

样例输出

(1,2)
(1,2)
(1,2)
(2,2)
(2,2)
(2,2)
(1,2)
3
#include<iostream>
#include<cstring>
#include<cstdio> using namespace std;
const int N = + ;
const int dir[][] = {{-, }, {, -}, {, }, {, }}; struct node{
int x, y, d;
}mat[N][N], p;
int a[]; int dirs_tran(int d, int x){
if(x == ) d = (d + ) % ; //左
if(x == ) d = (d + ) % ; //右
if(x == ) d = (d + ) % ; //后
return d;
} void dirs_work(int x){
p.d = dirs_tran(p.d, x);
} void moves_work(int x, int & cnt){
int cur;
if(x == ) cur = dirs_tran(p.d, );
if(x == ) cur = p.d;
if(x == ) cur = dirs_tran(p.d, );
if(x == ) cur = dirs_tran(p.d, );
int newx = p.x + dir[cur][], newy = p.y + dir[cur][];
if(newx > && newx <= && newy > && newy <=){
p.x = newx, p.y = newy;
if(!mat[newx][newy].d) { mat[newx][newy].d = ; cnt++; }
}
} void Solve_question(int n){
for(int i = ; i <= ; i ++)
for(int j = ; j <= ; j++) mat[i][j].d = ; int cnt = ;
p.x = , p.y = , p.d = ;
mat[][].d = ;
for(int i = ; i < n; i++){
if(a[i] >= && a[i] <= ) dirs_work(a[i]);
else moves_work(a[i], cnt);
printf("(%d,%d)\n",mat[p.x][p.y].x, mat[p.x][p.y].y);
}
printf("%d\n", cnt);
} void Init_mat(){
for(int i = ; i <= ; i++)
for(int j = ; j <= ; j++) mat[i][j] = (node) {j, -i}; }
int main(){
int n;
Init_mat();
scanf("%d", &n);
for(int i = ; i < n; i++) scanf("%d", &a[i]);
Solve_question( n ); }

最新文章

  1. Dynamics CRM 2015-Data Encryption激活报错
  2. 解决微信公众号OAuth出现40029(invalid code,不合法的oauth_code)的错误
  3. CF459B Pashmak and Flowers (水
  4. PHP flush sleep 输出缓存控制详解
  5. SQL索引一步到位
  6. DI 之 3.4 Bean的作用域(捌)
  7. python 抓取javascript 动态数据
  8. Apache HTTP Server mod_dav.c 拒绝服务漏洞(CVE-2013-1896)
  9. 从源码看Android中sqlite是怎么通过cursorwindow读DB的
  10. Storing and Retrieving Images from SQL Server using Microsoft .NET
  11. 【性能测试工具】- ApacheBench
  12. linux服务器 jboss-7安装
  13. 最简单有效的关于linux下配置Git操作免登录ssh公钥
  14. Grafana+Prometheus打造springboot监控平台
  15. 关于Mac OS虚拟机下共享文件夹的方法
  16. Flink - ShipStrategyType
  17. 顺序表的C、C++实现
  18. matlib实现梯度下降法(序一)
  19. debugfs文件系统
  20. 5、SourceTree使用git

热门文章

  1. PHP基础-表达式介绍
  2. mysql 创建用户和授权
  3. 【BZOJ2118】墨墨的等式(同余最短路)
  4. 在线前端 JS 或 HTML 或 CSS 编写 Demo 处 JSbin 与 jsFiddle 比较
  5. 用smtplib来发送邮件
  6. 也谈HTTP协议
  7. chrome 调试
  8. Vue的父子组件通信(转载)
  9. CentOS7 nginx安装与卸载
  10. java数字加密算法