NYOJ 92
1、深搜(会爆栈,通过开全局栈模拟递归)
爆栈代码
# include<iostream>
# include<string>
# include<string.h>
# include<queue>
# include<stdio.h>
# include<math.h>
#include <algorithm>
using namespace std;
int d[][];
void dfs(int i,int j)
{
if(d[i][j]==) return;
else
{
d[i][j] = ;
dfs(i-,j);
dfs(i+,j);
dfs(i,j-);
dfs(i,j+);
}
}
int main()
{
int n,m,i,j,w,h;
cin>>n;
while(n--)
{
cin>>w>>h;
d[0][0] = 1;
d[0][h+1] = 1;
d[w+1][0] = 1;
d[w+1][h+1] = 1;
for(i=;i<=w;i++)
{
for(j=;j<=h;j++)
{
if(i==) d[i-][j] = 1;
else if(i==w) d[i+][j] = 1;
else if(j==) d[i][j-] = 1;
else if(j==h) d[i][j+] = 1;
scanf("%d",&d[i][j]);
}
}
int flag = ;
for(i=;i<=w;i++)
{
for(j=;j<=h;j++)
{
if(d[i][j]!= && (i==||i==w||j==||j==h))
{
dfs(i,j);
break;
}
}
if(flag == ) break;
} for(i=;i<=w;i++)
{
for(j=;j<=h;j++)
{
printf("%d ",d[i][j]);
}
printf("\n");
} }
return ;
}
2、广搜(注意w,h输入顺序 先输入h后输入w)
# include<iostream>
# include<string>
# include<string.h>
# include<queue>
# include<stdio.h>
# include<math.h>
#include <algorithm>
using namespace std;
int d[][];
struct Node
{
int x,y;
}node,temp,f[];
queue<Node> q;
void bfs(int x,int y,int w,int h)
{
node.x = x;
node.y = y;
q.push(node);
d[x][y] = ;
while(!q.empty())
{
temp = q.front();
q.pop();
for(int i=;i<;i++)
{
int t1,t2;
t1 = temp.x + f[i].x;
t2 = temp.y + f[i].y;
if(t1>= && t1<=w+ && t2>= && t2<=h+ && d[t1][t2]!=)
{
d[t1][t2] = ;
node.x = t1;
node.y = t2;
q.push(node);
}
}
}
}
int main()
{
int n,m,i,j,w,h;
cin>>n;
f[].x = ;f[].y = ;
f[].x = ;f[].y = -;
f[].x = ;f[].y = ;
f[].x = -;f[].y = ;
while(n--)
{
//cin>>w>>h;
cin>>h>>w;
d[][] = ;
d[][h+] = ;
d[w+][] = ;
d[w+][h+] = ;
for(i=;i<=w;i++)
{
for(j=;j<=h;j++)
{
if(i==) d[i-][j] = ;
else if(i==w) d[i+][j] = ;
if(j==) d[i][j-] = ;
else if(j==h) d[i][j+] = ;
scanf("%d",&d[i][j]);
}
}
bfs(,,w,h);
for(i=;i<=w;i++)
{
for(j=;j<=h;j++)
{
printf("%d ",d[i][j]);
}
printf("\n");
} }
return ;
}
NYOJ 92的更多相关文章
- nyoj 92 图像有用区域
点击打开链接 图像有用区域 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 "ACKing"同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取 ...
- nyoj 92 图片实用面积【bfs】
图像实用区域 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 "ACKing"同学曾经做一个图像处理的项目时.遇到了一个问题,他须要摘取出图片中某 ...
- NYOJ 1007
在博客NYOJ 998 中已经写过计算欧拉函数的三种方法,这里不再赘述. 本题也是对欧拉函数的应用的考查,不过考查了另外一个数论基本定理:如何用欧拉函数求小于n且与n互质所有的正整数的和. 记eule ...
- 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)
建议88:用枚举实现工厂方法模式更简洁 工厂方法模式(Factory Method Pattern)是" 创建对象的接口,让子类决定实例化哪一个类,并使一个类的实例化延迟到其它子类" ...
- NYOJ 998
这道题是欧拉函数的使用,这里简要介绍下欧拉函数. 欧拉函数定义为:对于正整数n,欧拉函数是指不超过n且与n互质的正整数的个数. 欧拉函数的性质:1.设n = p1a1p2a2p3a3p4a4...pk ...
- Entity Framework 6 Recipes 2nd Edition(9-2)译->用WCF更新单独分离的实体
9-2. 用WCF更新单独分离的实体 问题 你想通过WCF为一个数据存储发布查询,插入,删除和修改,并且使这些操作尽可能地简单 此外,你想通过Code First方式实现EF6的数据访问管理 解决方案 ...
- NYOJ 333
http://www.cppblog.com/RyanWang/archive/2009/07/19/90512.aspx?opt=admin 欧拉函数 E(x)表示比x小的且与x互质的正整数的个数. ...
- 用python实现计算1-2*((60-30+(-40/5)*(9-2*5/3+7/3*99/4*2998+10*568/14))-(-4*3)/(16-3*2))类似的公式计算
作业需求: 开发一个简单的python计算器 1.实现加减乘除及拓号优先级解析 2.用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 ...
- KBMMW 4.92.00 发布
We are happy to announce the release of kbmMW Professional and Enterprise Edition. Yet again kbmMW c ...
随机推荐
- 艺多不压身 -- 常用缓存Cache机制的实现
常用缓存Cache机制的实现 缓存,就是将程序或系统经常要调用的对象存在内存中,以便其使用时可以快速调用,不必再去创建新的重复的实例. 这样做可以减少系统开销,提高系统效率. 缓存主要可分为二大类: ...
- Git 学习笔记--删除错误提交的commit
如果不小心把错误的commit给commit了,可以对其进行撤销 1.使用git log查看commit日志,找到错误提交前一版本commit的哈希值; 2.使用git reset --hard co ...
- Fiddler 使用命令行
在 Fiddler 界面左下角处,可以输出一些快捷命令,常用的快捷命令如下: help:查看命令帮助cls:清屏,即清空会话列表中的所有会话select:选择某一类型的会话,如 select html ...
- 7.11js常用对象
<!DOCTYPE html> <html> <head> <title>js常用对象</title> <script type=&q ...
- postgresql----聚合函数
聚合函数是从一组输入中计算出一个结果的函数. 测试表 test=# \d tbl_test Table "public.tbl_test" Column | Type | Modi ...
- lxml基础
节点操作: from lxml import etree # 1.创建Element对象,参数即节点名称 root = etree.Element('root') print(root) # < ...
- 如何写好.babelrc?Babel的presets和plugins配置解析
什么是Babel The compiler for writing next generation JavaScript. 官网是这么说的,翻译一下就是下一代JavaScript 语法的编译器. 作为 ...
- Chap8:加密货币TOP100[《区块链中文词典》维京&甲子]
根据2018年1月15日CoinMarketCap的加密货币市值排名编写,这里介绍TOP10,具体请参考<区块链中文词典>维京&甲子 01.比特币/Bitcoin/BTC 一种点对 ...
- iOS中的静态库与动态库,区别、制作和使用
如果我们有些功能要给别人用,但是又不想公开代码实现,比如高德地图.第三方登录分享等等,这时候我们就要打包成库了.库分静态库和动态库两种: 静态库:以.a 和 .framework为文件后缀名.动态库: ...
- xcode工程编译错误:一般错误总结
1.Apple LLVM 8.0 Error Group /’all-product-headers.yaml’ not found 最近升级了xcode打包后出现了个BUG,记录解决的方法. 现象: ...