主题链接:HDU 2414 Chessboard Dance

意甲冠军:鉴于地图,>,<,^,v的方向,字母相当于是箱子,箱子能够推出边界。人保证不会做出边界。以下输入指令,依照指令走,输出结束时图的状态。

强行模拟一遍,注意以下给出的案例。

>t.p.p.p
...a....
........
...bfg.y
...c...
...d....
...e....
........
move 3
turn right
move 3
turn left
move 3
turn left
move 3
#

AC代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=20;
char mp[maxn][maxn];
queue<char> q;
int get_dir(int x,int y)
{
if(mp[x][y]=='^')
return 1;
else if(mp[x][y]=='>')
return 2;
else if(mp[x][y]=='v')
return 3;
else if(mp[x][y]=='<')
return 4;
} void out()
{
int i,j;
//printf("---------------------\n");
for(i=0; i<8; i++)
{
for(j=0; j<8; j++)
printf("%c",mp[i][j]);
printf("\n");
}
printf("\n");
} int main()
{
int i,j;
int dir,x,y;
char scr[20];
while(scanf("%s",mp[0])!=EOF)
{
if(strcmp(mp[0],"--")==0)
break;
while(!q.empty())
q.pop();
for(i=1; i<8; i++)
scanf("%s",mp[i]);
for(i=0; i<8; i++)
{
for(j=0; j<8; j++)
{
if(mp[i][j]=='>' || mp[i][j]=='^' || mp[i][j]=='<' || mp[i][j]=='v')
{
x=i;
y=j;
dir=get_dir(x,y);
break;
}
}
}
//out();
while(1)
{
scanf("%s",scr);
if(strcmp(scr,"#")==0)
break;
while(!q.empty())
q.pop();
if(strcmp(scr,"move")==0)
{
int ss;
scanf("%d",&ss);
if(dir==1)//向上
{
int temp;
if(ss>=x)//!走出边界
{
temp=x;
for(i=x;i>=0;i--)
mp[i][y]='.';
mp[x=0][y]='^';
}
else
{
mp[x][y]='.';
int temp=x-1;
int cont=ss;
while(cont--)
{
while(mp[temp][y]!='.' && temp>=0)
{
q.push(mp[temp][y]);
mp[temp][y]='.';
temp--;
}
temp--;
}
temp=x-ss;
mp[x=temp--][y]='^';
for(;temp>=0 && !q.empty();temp--)
{
mp[temp][y]=q.front();
q.pop();
}
}
//out();
}
else if(dir==2)//向右
{
int temp;
if(ss>=7-y)//!走出边界
{
temp=7-y;
for(i=y;i<8;i++)
mp[x][i]='.';
mp[x][y=7]='>';
}
else
{
mp[x][y]='.';
int temp=y+1;
int cont=ss;
while(cont--)
{
while(mp[x][temp]!='.' && temp<8)
{
q.push(mp[x][temp]);
mp[x][temp]='.';
temp++;
}
temp++;
}
temp=y+ss;
mp[x][y=temp++]='>';
for(;temp<8 && !q.empty();temp++)
{
mp[x][temp]=q.front();
q.pop();
}
}
//out();
}
else if(dir==3)//向下
{
int temp;
if(ss>=7-x)//!走出边界
{
temp=7-x;
for(i=x;i<8;i++)
mp[i][y]='.';
mp[x=7][y]='v';
}
else
{
mp[x][y]='.';
int temp=x+1;
int cont=ss;
while(cont--)
{
while(mp[temp][y]!='.' && temp<8)
{
q.push(mp[temp][y]);
mp[temp][y]='.';
temp++;
}
temp++;
}
temp=x+ss;
mp[x=temp++][y]='v';
for(;temp<8 && !q.empty();temp++)
{
mp[temp][y]=q.front();
q.pop();
}
}
//out();
}
else if(dir==4)//向左
{
int temp;
if(ss>=y)//!走出边界
{
temp=y;
for(i=y;i>=0;i--)
mp[x][i]='.';
mp[x][y=0]='<';
}
else
{
mp[x][y]='.';
int temp=y-1;
int cont=ss;
while(cont--)
{
while(mp[x][temp]!='.' && temp>=0)
{
q.push(mp[x][temp]);
mp[x][temp]='.';
temp--;
}
temp--;
}
temp=y-ss;
mp[x][y=temp--]='<';
for(;temp>=0 && !q.empty();temp--)
{
mp[x][temp]=q.front();
q.pop();
}
}
//out();
}
}
else if(strcmp(scr,"turn")==0)
{
char cc[20];
scanf("%s",cc);
if(strcmp(cc,"left")==0)
{
if(dir==1) dir=4,mp[x][y]='<';
else if(dir==2) dir=1,mp[x][y]='^';
else if(dir==3) dir=2,mp[x][y]='>';
else if(dir==4) dir=3,mp[x][y]='v';
}
else if(strcmp(cc,"right")==0)
{
if(dir==1) dir=2,mp[x][y]='>';
else if(dir==2) dir=3,mp[x][y]='v';
else if(dir==3) dir=4,mp[x][y]='<';
else if(dir==4) dir=1,mp[x][y]='^';
}
else if(strcmp(cc,"back")==0)
{
if(dir==1) dir=3,mp[x][y]='v';
else if(dir==2) dir=4,mp[x][y]='<';
else if(dir==3) dir=1,mp[x][y]='^';
else if(dir==4) dir=2,mp[x][y]='>';
}
//out();
}
}
out();
}
return 0;
}
/*
.....c..
.p..A..t
D..>T.Pr
....aP.P
p.d.C...
.....p.R
........
........
move 5 .....c..
.p..A..t
D..>T.Pr
....aP.P
p.d.C...
.....p.R
........
........
move 1
turn left
move 99
turn back
move 6
#
.....c..
.p.....t
D....TPr
.....P.P
p.d.C...
.....p.R
....v...
....a... >t.p.p.p
...a....
........
...bfg.y
...c...
...d....
...e....
........
move 3
turn right
move 3
turn left
move 3
turn left
move 3
# .>ta.cb.
........
........
........
........
........
........
........
move 3
#
*/

版权声明:本文博主原创文章,博客,未经同意不得转载。

HDU 2414 Chessboard Dance (力模拟)的更多相关文章

  1. POJ 3344 &amp; HDU 2414 Chessboard Dance(模拟)

    题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...

  2. HDU 2414 Chessboard Dance(模拟题,仅此纪念我的堕落)

    题目 模拟题也各种wa,我最近真的堕落了,,,,,智商越来越为负数了!!!!!!!! #include<stdio.h> #include<string.h> #include ...

  3. 【HDOJ】2414 Chessboard Dance

    简单DFS. /* 2414 */ #include <cstdio> #include <cstring> #include <cstdlib> ; ][]; i ...

  4. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  5. 洛谷 P2033 Chessboard Dance

    P2033 Chessboard Dance 题目描述 在棋盘上跳舞是件有意思的事情.现在给你一张国际象棋棋盘和棋盘上的一些子以及你的初始位置和方向.求按一定操作后,棋盘的状态. 操作有四种,描述如下 ...

  6. UVALive 4222 /HDU 2961 Dance 大模拟

    Dance Problem Description For a dance to be proper in the Altered Culture of Machinema, it must abid ...

  7. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  8. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  9. HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. 上delloc 无呼叫 故障排除 笔记

    经验 delloc 无呼叫 基本上可以得出结论,即循环引用的原因. 遇到这样的情况基本上可分为 1: 属性声明weak的地方 写成了 strong  .比方delegate. 2: block语法块中 ...

  2. Eclipse with C++: "Launch failed. Binary not found."

    Eclipse with C++:  "Launch failed. Binary not found." (windows 7) 用Eclipse创建一个Hello world ...

  3. HTML5 在canvas绘制一个矩形

    笔者:本笃庆军 原文地址:http://blog.csdn.net/qingdujun/article/details/32930501 一.绘制矩形 canvas使用原点(0,0)在左上角的坐标系统 ...

  4. 前端构建工具gulp

    前端构建工具gulp使用   前端自动化流程工具,用来合并文件,压缩等. Gulp官网 http://gulpjs.com/ Gulp中文网 http://www.gulpjs.com.cn/ Gul ...

  5. Ubuntu 如何重新安裝 Unity ?

    阿舍在刪除 Qt 的時候下錯指令,結果,就把 Unity 給移除掉了,雖然,阿舍從此就知道 Unity 和 Qt 有不分離的關係,不過,就沒有Unity可以用了,這樣阿舍要試東西就不是很方便了哩 ! ...

  6. 重新想象 Windows 8 Store Apps (8) - 控件之 WebView

    原文:重新想象 Windows 8 Store Apps (8) - 控件之 WebView [源码下载] 重新想象 Windows 8 Store Apps (8) - 控件之 WebView 作者 ...

  7. 【Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之三】动手绑定自己定义类至Lua

        查看[Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之二]新建项目中配制环境,我们完美的在新建项目中完毕了绑定须要的环境,接下来才是最关健的一步.绑定自己定义C++类至Lu ...

  8. Docker部署JavaWeb项目实战(转)

    摘要:本文主要讲了如何在Ubuntu14.04 64位系统下来创建一个运行Java web应用程序的Docker容器. 一.下载镜像.启动容器 1.下载镜像 先查看镜像 docker images 记 ...

  9. ASCII与Unicode编码消息写文件浅析

    [文章摘要] ASCII与Unicode是两种常见的字符编码. 它们的表示方法不一样,因而在程序中就要差别处理. 本文基于作者的实际开发经验,对ASCII与Unicode两种字符编码消息的写文件过程进 ...

  10. CentOS 5 安装Oracle10g

    原创作品.离 "深蓝的blog" 博客.欢迎转载.转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlon ...