【HDOJ】2414 Chessboard Dance
简单DFS。
/* 2414 */
#include <cstdio>
#include <cstring>
#include <cstdlib> const int n = ;
char map[][];
int x, y, d;
char dirs[] = "^v<>";
int dir[][] = {
-,, ,, ,-, ,
};
int tdir[][] = {
,,, ,,, ,,, ,,
}; inline bool check(int x, int y) {
return x< || x>=n || y< || y>=n;
} void dfs(int x, int y) {
int i, j, k;
int xx, yy; xx = x + dir[d][];
yy = y + dir[d][];
if (check(xx, yy))
return ;
if (map[xx][yy] == '.') {
map[xx][yy] = map[x][y];
map[x][y] = '.';
} else {
dfs(xx, yy);
map[xx][yy] = map[x][y];
map[x][y] = '.';
}
} int main() {
int i, j, k;
char cmd[];
int xx, yy; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (scanf("%s", map[]) != EOF) {
if (map[][]=='-' && map[][]=='-' && map[][]=='\0')
break;
for (i=; i<; ++i)
scanf("%s", map[i]);
for (i=; i<; ++i) {
for (j=; j<; ++j) {
if (map[i][j] == '^') {
x = i;
y = j;
d = ;
} else if (map[i][j] == 'v') {
x = i;
y = j;
d = ;
} else if (map[i][j] == '<') {
x = i;
y = j;
d = ;
} else if (map[i][j] == '>') {
x = i;
y = j;
d = ;
}
}
}
while (scanf("%s", cmd)!=EOF && cmd[]!='#') {
if (cmd[] == 'm') {
// move
scanf("%d", &k);
while (k--) {
xx = x + dir[d][];
yy = y + dir[d][];
if (check(xx, yy))
break;
dfs(x, y);
x = xx;
y = yy;
}
} else {
// turn
scanf("%s", cmd);
if (cmd[] == 'l') {
d = tdir[d][];
} else if (cmd[] == 'r') {
d = tdir[d][];
} else {
d = tdir[d][];
}
}
}
map[x][y] = dirs[d];
for (i=; i<; ++i) {
map[i][] = '\0';
puts(map[i]);
}
putchar('\n');
} return ;
}
【HDOJ】2414 Chessboard Dance的更多相关文章
- HDU 2414 Chessboard Dance (力模拟)
主题链接:HDU 2414 Chessboard Dance 意甲冠军:鉴于地图,>,<,^,v的方向,字母相当于是箱子,箱子能够推出边界.人保证不会做出边界.以下输入指令,依照指令走,输 ...
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
随机推荐
- Bash从路径中获取文件名
#!/bin/bash basename /etc/hosts
- td中使用overflow:hidden; 无效解决方案
td中使用overflow:hidden; 无效解决方案 >>>>>>>>>>>>>>>>>> ...
- CI框架篇之控制器篇--设置路由(1)
CodeIgniter 定义默认控制器 当你的网站不存在某个URI 或者 用户直接从根目录访问的时候,CodeIgniter 会加载默认控制器. 打开 application/config/route ...
- MICROSOFT REPORT VIEWER 2012之无法加载相关的dll
使用VS 2012开发报表, 如果是使用的微软的报表控件的话,默认是使用的MICROSOFT REPORT VIEWER 2012,本地开发基本上没问题,但是一发布服务器,就会发现坑了,微软挖坑从来就 ...
- centos7 安装php5.6.0 、nginx1.7.4、phpssdbadmin
1 创建用户.网站目录和下载相关的安装包 groupadd www #添加www组 创建目录/data/www/ chown www:www /data/www/ -R #设置目录所有者 chmod ...
- Chart图形 [功能帮助类] Assistant创建显示图像的标签和文件 (转载)
点击下载 Assistant.zip /// <summary> /// 类说明:Assistant /// 联系方式:361983679 /// 更新网站:[url=http://www ...
- Js 上传文件 页面不刷新
html控件代码: <form id="form1"> <p><input type="file" name="mfil ...
- PL/SQL 中文转换为\uxxxx格式(unicode)
用plsql生成json的时候,经常要处理中文的情况. SELECT replace(asciistr('你好,,hello'),'\','\u') FROM dual 输出:\u4F60\u597D ...
- js--Ajax的小知识(二):处理ajax的session过期的请求
问题的产生: 现如今Ajax在Web项目中应用广泛,几乎可以说无处不在. 有时会碰到这样个问题:当Ajax请求遇到Session超时,应该怎么办? 显而易见,传统的页面跳转在此已经不适用,因为Ajax ...
- Oracle 日期类型timestamp(时间戳)和date类型使用
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...