文档章节

ZOJ Problem Set - 2100

 木宛城主
发布于 2015/03/02 19:42
字数 468
阅读 1
收藏 0
点赞 0
评论 0
ZOJ Problem Set - 2100
Seeding
Time Limit: 1 Second       Memory Limit: 32768 KB
It is spring time and farmers have to plant seeds in the field. Tom has a nice field, which is a rectangle with n * m squares. There are big stones in some of the squares.

Tom has a seeding-machine. At the beginning, the machine lies in the top left corner of the field. After the machine finishes one square, Tom drives it into an adjacent square, and continues seeding. In order to protect the machine, Tom will not drive it into a square that contains stones. It is not allowed to drive the machine into a square that been seeded before, either.

Tom wants to seed all the squares that do not contain stones. Is it possible?


Input

The first line of each test case contains two integers n and m that denote the size of the field. (1 < n, m < 7) The next n lines give the field, each of which contains m characters. 'S' is a square with stones, and '.' is a square without stones.

Input is terminated with two 0's. This case is not to be processed.


Output

For each test case, print "YES" if Tom can make it, or "NO" otherwise.


Sample Input

4 4
.S..
.S..
....
....
4 4
....
...S
....
...S
0 0


Sample Output

YES
NO

=============

典型的DFS题,很不错。

题目很简单,从左上角出发,判断是否能完全把地耕玩(拖拉机不能在石块和已经耕好的地上行驶。

#include <stdio.h>
#include <string.h>
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};//四个方向 
char map[10][10];//定义一张地图 
int done;
int Flag;
int n,m;
void dfs(int x,int y) 
{
  int i;
  if(x<1 || y<1 || x>n || y>m)   return;//判断是否越界  
  done++; 
  if(done==n*m)//如果成功则返回 
  {
     Flag=1;
     return;
  }
  for(i=0;i<4;i++)
  {
     if(map[x+dir[i][0]][y+dir[i][1]]=='.')
     {
	 
	     map[x+dir[i][0]][y+dir[i][1]]='S';//标记已经耕过的土地 
	     dfs(x+dir[i][0],y+dir[i][1]);
	 }
  }
  done--;
  map[x][y]='.';
}
int main()
{
   int i,j;  
   memset(map,'S',sizeof(map));
   while(scanf("%d%d%*c",&n,&m)!=EOF)
   {
      if(n==0 && m==0)
      break;
      done=0;
      Flag=0;
      for(i=1;i<=n;i++)
      {
	     
		 for(j=1;j<=m;j++)
	     {
		    scanf("%c",&map[i][j]);
		    if(map[i][j]=='S')
		    done++;
		 }
		 getchar();
	  
	  }
	 	 
	  map[1][1]='S';
	  dfs(1,1);
	  if(Flag==1)
	  printf("YES\n");
	  else
	  printf("NO\n");
   }
return 0;

}

© 著作权归作者所有

共有 人打赏支持
粉丝 2
博文 222
码字总数 199010
作品 0
黄浦
ACM Summer Training Warm up

ACM Summer Training Warm up Cover 热身水题 题目 HDU 4500 小Q系列故事——屌丝的逆袭 思路 简单的模拟,一个数组读入数据,一个数组计算维护结果 HDU 2109 Fighting for HDU 思路 简单排序...

SpiffyEight77 ⋅ 2017/08/14 ⋅ 0

使用ZooKeeper

安装好 ZooKeeper 之后,可以使用telnet来测试是否运行。 这里使用的是单机 standalone 模式。 也可以使用客户端脚本来连接服务器 连接上之后就可以像使用 NOSQL(memcached,redis) 数据库一样...

兔之 ⋅ 2015/10/12 ⋅ 0

ZOJ Problem Set - 1016 Parencodings

Parencodings Time Limit: 2 Seconds Memory Limit: 65536 KB Let S = s1 s2 ... s2n be a well-formed string of parentheses. S can be encoded in two different ways: By an integer seq......

hushhw ⋅ 2017/11/27 ⋅ 0

ZOJ Problem Set - 2104 Let the Balloon Rise(map)

Let the Balloon Rise Time Limit: 2 Seconds Memory Limit: 65536 KB Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' fa......

hushhw ⋅ 2017/11/27 ⋅ 0

ZOJ Problem Set - 1094 Matrix Chain Multiplication

Matrix Chain Multiplication Time Limit: 2 Seconds Memory Limit: 65536 KB Matrix multiplication problem is a typical example of dynamical programming. Suppose you have to evaluat......

hushhw ⋅ 2017/11/27 ⋅ 0

ZOJ Problem Set - 1004 Anagrams by Stack

Anagrams by Stack Time Limit: 2 Seconds Memory Limit: 65536 KB How can anagrams result from sequences of stack operations? There are two sequences of stack operators which can c......

hushhw ⋅ 2017/11/27 ⋅ 0

USG防火墙

为什么?保证内网安全 阻止外网攻击 场景:内网和外网的边界 安全区域: 配置 firewall zone trust 进入安全区域 add int g0/0/1 加入接口所属网段 默认0口属于trust 安全区域的优先级不允许...

我的中国 ⋅ 02/09 ⋅ 0

mysql-mmm配置文档--下

四、主主(master-master)同步配置 1)172.16.71.132机器my.cnf skip-name-resolve server_id = 132 set-variable = keybuffersize=512M set-variable = table_cache=32 set-variable = sor......

qwjhq ⋅ 2010/12/13 ⋅ 0

ZOJ Problem Set - 1003Crashing Balloon

Crashing Balloon Time Limit: 2 Seconds Memory Limit: 65536 KB On every June 1st, the Children's Day, there will be a game named "crashing balloon" on TV. The rule is very simple......

hushhw ⋅ 2017/11/21 ⋅ 0

Warzone 2100 3.1.2 发布,即时战略游戏

即时战略游戏 Warzone 2100 发布了 3.1.2 更新版本,下载地址: https://sourceforge.net/projects/warzone2100/files/releases/3.1.2/ 改进记录请看: https://github.com/Warzone2100/war......

oschina ⋅ 2014/12/31 ⋅ 9

没有更多内容

加载失败,请刷新页面

加载更多

下一页

android -------- 颜色的半透明效果配置

最近有朋友问我 Android 背景颜色的半透明效果配置,我网上看资料,总结了一下, 开发中也是常常遇到的,所以来写篇博客 常用的颜色值格式有: RGB ARGB RRGGBB AARRGGBB 这4种 透明度 透明度...

切切歆语 ⋅ 6分钟前 ⋅ 0

CentOS开机启动subversion

建立自启动脚本: vim /etc/init.d/subversion 输入如下内容: #!/bin/bash## subversion startup script for the server## chkconfig: 2345 90 10# description: start the subve......

随风而飘 ⋅ 9分钟前 ⋅ 0

Nginx + uwsgi @ubuntu

Nginx 安装 & 启动 sudo apt-get install nginx  #安装fnngj@ubuntu:~$ /etc/init.d/nginx start  #启动fnngj@ubuntu:~$ /etc/init.d/nginx stop  #关闭fnngj@ubuntu:~$ /etc/init.d/......

袁祾 ⋅ 10分钟前 ⋅ 0

版本控制工具

CSV , SVN , GIT ,VSS

颖伙虫 ⋅ 12分钟前 ⋅ 0

【2018.06.19学习笔记】【linux高级知识 13.1-13.3】

13.1 设置更改root密码 13.2 连接mysql 13.3 mysql常用命令

lgsxp ⋅ 20分钟前 ⋅ 0

LVM

LVM: 硬盘划分分区成物理卷->物理卷组成卷组->卷组划分逻辑分区。 1.磁盘分区: fdisk /dev/sdb 划分几个主分区 输入t更改每个分区类型为8e(LVM) 使用partprobe生成分区的文件:如/dev/sd...

ZHENG-JY ⋅ 48分钟前 ⋅ 0

彻底删除Microsoft Office的方法

参照此链接彻底删除Office https://support.office.com/zh-cn/article/%e4%bb%8e-pc-%e5%8d%b8%e8%bd%bd-office-9dd49b83-264a-477a-8fcc-2fdf5dbf61d8?ui=zh-CN&rs=zh-CN&ad=CN......

Kampfer ⋅ 今天 ⋅ 0

大盘与个股之间关系

大盘走多:积极出手 顺势加码 大盘走空: 少量出手 退场观望 大盘做头:逆势减码 少量操作 大盘做底 : 小量建仓 小量试单

guozenhua ⋅ 今天 ⋅ 0

Day16 LVM(逻辑卷管理)与磁盘故障小案例

lvm详解 简述 LVM的产生是因为传统的分区一旦分区好后就无法在线扩充空间,也存在一些工具能实现在线扩充空间但是还是会面临数据损坏的风险;传统的分区当分区空间不足时,一般的解决办法是再...

杉下 ⋅ 今天 ⋅ 0

rsync实现多台linux服务器的文件同步

一、首先安装rsync,怎样安装都行,rpm,yum,还是你用源码安装都可以。因为我用的是阿里云的ESC,yum install rsync就ok了。 二、配置rsync服务 1.先建立个同步数据的帐号 123 groupadd r...

在下头真的很硬 ⋅ 今天 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部