【BZOJ】1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛
Description
经过跟Farmer John长达数年的谈判,奶牛们终于如愿以偿地得到了想要的旱冰鞋。农场上大部分的区域都很平整,适合在上面滑动,但有一些小块的土地上有很多的岩石,凭奶牛们的旱冰技术,是没有办法通过的。 农场可以看成一个被划分成R(1<=R<=113)行C(1<=C<=77)列的矩阵。快要开饭了,贝茜发现自己在坐标为(1,1)的格子里,并且她想赶到坐标为(R,C)的牛棚去享用她的晚饭。贝茜知道,以她所在的格子为起点,每次向上、下、左、右滑动(但不能沿对角线滑动),一定能找到一条通往牛棚的、不经过任何有大量岩石的格子的路。请你为她指出任意一条通往牛棚的路径。
Input
* 第1行: 两个用空格隔开的整数,R和C * 第2..R+1行: 每行包含C个字符(不含空格),字符只可能是'.'或'*'。是'.' 的话,表示贝茜能从这个格子里通过,是'*'的话,则这个格子 是不能通过的多岩石地带
Output
* 第1..?行: 每行包含2个用空格隔开的整数,表示贝茜回牛棚路径所通过的格 子的坐标。输出的第一行显然应该是1 1,最后一行是R C。输出中 的其余行,依次给出路径中格子的坐标,相邻的两个坐标所表示的 格子必须相邻。
Sample Input
..*...**
*.*.*.**
*...*...
*.*.*.*.
....*.*.
Sample Output
1 2
2 2
3 2
3 3
3 4
2 4
1 4
1 5
1 6
2 6
3 6
3 7
3 8
4 8
5 8
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int MAXN = 114; const int mx[] = { 1, -1, 0, 0 }; const int my[] = { 0, 0, 1, -1 }; struct xx {int x, y; }; xx a[MAXN]; char g[MAXN][MAXN]; bool use[MAXN][MAXN]; int n, m; int cnt; bool check(int x, int y) {if (use[x][y] == false) return false;if (x > n || x<1 || y>m || y < 1) return false;return true; } inline void add(int x, int y) {if (g[x][y] == '.') use[x][y] = true;else use[x][y] = false; } void dfs(int x, int y) {int i;if (x == n&&y == m){for (i = 1; i <= cnt; i++){printf("%d %d\n", a[i].x, a[i].y); }exit(0);}for (i = 0; i <= 3; i++){int tx = x + mx[i];int ty = y + my[i];if (check(tx, ty)){//cout << tx << ' ' << ty << endl;a[++cnt].x = tx, a[cnt].y = ty;use[tx][ty] = false;dfs(tx, ty);cnt--;use[tx][ty] = true;}} } int main(int argc, char *argv[]) {int i, j, x, y;scanf("%d%d", &n, &m);for (i = 1; i <= n; i++){scanf("%s", g[i] + 1);for (j = 1; j <= m; j++)add(i, j);}puts("1 1");dfs(1, 1);return 0; }
转载于:https://www.cnblogs.com/BeyondW/p/5959060.html
【BZOJ】1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛相关推荐
- bzoj 1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛(BFS)
1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛 Time Limit: 1 Sec Memory Limit: 64 MBSec Special Judge S ...
- BFS【bzoj1667】: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛
1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛 Description 经过跟Farmer John长达数年的谈判,奶牛们终于如愿以偿地得到了想要的旱冰鞋.农场上大 ...
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 990 Solved: 64 ...
- bzoj 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富(DP)
1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 786 So ...
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 624 Sol ...
- bzoj:1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶 ...
- bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 用叉积判断.注意两端的平行于 y 轴的. #include<cstdio> ...
- 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)...
链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛*
bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛 题意: 求最长单调递增子序列,序列大小≤5000 题解: 蒟蒻弱写了一个O(n^2)的. 代码: 1 #include ...
最新文章
- rabbit-mq cluster安装
- android从放弃到精通 第一天 重拾项目开发
- 管理Exchange服务器
- linux 中使用 crontab 执行定时任务
- 设计模式(4)--AbstractFactory(抽象工厂模式)--创建型
- 变长参数模板 和 外部模板
- jzoj4224-食物【多重背包】
- 苹果更新未知错误17_iOS 13 新功能,静音未知来电
- springmvc防止重复提交拦截器
- HTML5 中Web存储问题
- bootstrap 图标和文字对齐
- php安装调式redis扩展,下载安装thinkphp5.0,调试Redis是否可以正常使用
- NRF24L01模块的2个注意点
- 计算机内存die,从内存时序的角度告诉你 三星B-DIE为何成为高端所用
- 计算机地图制图的优点,计算机地图制图实习报告.doc
- isc dhcp 服务器性能,DHCP 服务器搭建问题
- java 打印 边距_缩小边距 – Java打印
- 瓶中阳光——雪莉之美
- 201671010412 郭佳 实验三 作业互评与改进
- 百度百科如何创建词条|多少钱
热门文章
- python写一个游戏多少代码-使用50行Python代码从零开始实现一个AI平衡小游戏
- python爬虫招聘-Python爬虫抓取智联招聘(基础版)
- python贴吧爬虫-Python 爬虫练习: 爬取百度贴吧中的图片
- python常用内置函数总结-python 几个常用的内置函数
- 自学python需要多长时间-零基础学习Python开发需要多长时间?
- python要学多久-零基础python培训需要学多久?
- 自学python需要下载什么软件-一个零基础学习Python应该知道的学习步骤与规划
- python编程有哪些-Python编程开发都有哪些限制
- python教学视频-Python入门视频课程
- python中的time库安装步骤-Python中time模块的使用