uva 352 - The Seasonal War
題意:
要確認畫面中有幾隻Eagles,每個pixel如果是'1'代表為一隻Eagles,但上下左右(包含斜角共8個方向)相連的'1'只能算是同一隻。
想法:
使用DFS找'1'有幾個區域。
#include <cstdio>
using namespace std; char image[][]; void DFS(int &n, int i, int j)
{
image[i][j] = '';
if (i- >= && image[i-][j] == '') DFS(n, i-, j);
if (i+ < n && image[i+][j] == '') DFS(n, i+, j);
if (j- >= && image[i][j-] == '') DFS(n, i, j-);
if (j+ < n && image[i][j+] == '') DFS(n, i, j+);
if (i- >= && j- >= && image[i-][j-] == '') DFS(n, i-, j-);
if (i- >= && j+ < n && image[i-][j+] == '') DFS(n, i-, j+);
if (i+ < n && j- >= && image[i+][j-] == '') DFS(n, i+, j-);
if (i+ < n && j+ < n && image[i+][j+] == '') DFS(n, i+, j+);
} int main()
{
// freopen ("input.txt","rt",stdin);
int n,Case = ;
while (scanf("%d", &n) != EOF){
getchar();
for (int i = ; i < n; ++i)
gets(image[i]);
int num = ;
for (int i = ; i < n; ++i)
for (int j = ; j < n; ++j)
if (image[i][j] == ''){
DFS(n, i, j);
++num;
}
printf("Image number %d contains %d war eagles.\n", Case++, num);
}
return ;
}
uva 352 - The Seasonal War的更多相关文章
- UVA352 The Seasonal War
本文为UserUnknown原创 题目本身不难理解,就是深搜(或广搜,有可能以后会加在这里). 但是洛谷的题目中没有截到输入输出的格式,下面是我从UVA复制下来的样例: Sample input 6 ...
- UVA - 10032 Tug of War (二进制标记+01背包)
Description Problem F: Tug of War A tug of war is to be arranged at the local office picnic. For the ...
- 使用maven多模块来构建系统时,spring初始化报错的问题
最近在实验maven结构的maven工程时,碰到一个问题,springbean总是初始化失败: Related cause: org.springframework.beans.factory.Uns ...
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- 贪心 UVA 11729 Commando War
题目传送门 /* 贪心:按照执行时间长的优先来排序 */ #include <cstdio> #include <algorithm> #include <iostrea ...
- cogs 1446. [Commando War,Uva 11729]突击战
1446. [Commando War,Uva 11729]突击战 ★ 输入文件:commando.in 输出文件:commando.out 简单对比时间限制:1 s 内存限制:64 ...
- [ACM_水题] UVA 11729 Commando War [不可同时交代任务 可同时执行 最短完成全部时间 贪心]
There is a war and it doesn't look very promising for your country. Now it's time to act. You have a ...
- UVA 11729 - Commando War(贪心 相邻交换法)
Commando War There is a war and it doesn't look very promising for your country. Now it's time to ac ...
随机推荐
- 使用C#版本GDAL读取复数图像
GDAL的C#版本虽然在很多算法接口没有导出,但是在读写数据中的接口基本上都是完全导出了.使用ReadRaster和WriteRaster方法来进行读写,同时对这两个方法进行了重载,对于常用的数据类型 ...
- Razor视图引擎
在MVC3.0版本的时候,微软终于引入了第二种模板引擎:Razor.在这之前,我们一直在使用WebForm时代沿留下来的ASPX引擎或者第三方的NVelocity模板引擎. (1)Razor文件类型: ...
- python_基本语法_01
离毕业工作还有几个月,本来想早点去公司实习,无奈gb学校不给放.好吧,既然这样,就学门语言. 参考与 http://www.cnblogs.com/vamei ,我是跟着这位博客牛人的博客教程学的,具 ...
- js中将函数传递给另一个函数的解析(非常容易理解)
$(document).ready(function(){ //JS中关于把函数作为函数的参数来传递的问题的小总结//第一,最简单的形式无参函数,直接形式函数的函数名放到括号中,再在执行部分这个函数即 ...
- ViewPager+Fragment的结合使用,实现QQ界面的理解
http://www.cssxt.com/html/2449/2449.html 效果如图: 实现代码解析:MainActivity.java1.引入布局文件2.4个标题控件的初始化以及点击事件的监听 ...
- 常用cl命令参数解释
紧接前文,第一行cl命令如下: 1> cl /c /IC:\...\include /ZI /nologo- /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG ...
- Groovy简洁开发,我用到的简洁之处
最近一直在用Groovy开发以前的项目,一边学习一边开发,工具用的是IDEA(欲哭无泪,不熟悉真是搞死人).......由于我做的是服务层,是为公司其它项目做服务支撑的,所以就没有用框架,只有一些se ...
- 原生js实现轮播
1,效果图 https://ga20.github.io/slider/ 2,原理图 分三步: 将视口元素设置overflow:hidden 将其图片子元素设置float:left 让橙色的框(包裹) ...
- SpringMVC+highstock实现曲线报表
最近项目要做曲线报表,之前用的是生成图片然后传到前端,感觉不是很好,在网上找到资料说highstock就可以而且还可以做类似股票的那种实时的曲线,研究的一段时间把项目问题解决了做个总结: 首先把hig ...
- poj 3181 Dollar Dayz (整数划分问题---递归+DP)
题目:http://poj.org/problem?id=3181 思路:将整数N划分为一系列正整数之和,最大不超过K.称为整数N的K划分. 递归:直接看代码: 动态规划:dp[i][j]:=将整数i ...