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 ...
随机推荐
- 猜数字-js
var n = Math.round(Math.random()*10); //随机数 // alert(n); while(true){ var Onum = prompt('请输入1-10之间的数 ...
- DEDE提高生成HTmL的速度
1.找到include/inc/inc_fun_SpGetArcList.php打开之. 2.查找以下代码: for($i=0;$i<$ridnum;$i++){ if($tps ...
- var genreModel =storeDB.Genres.Include("Albums").Single(g => g.Name == genre);是什么意思?
g => g.Name == genre代表一个匿名函数.即这里向Single方法传入了一个方法类型的参数. =>左边的g代表方法的参数,可以有多个,如(g,f) => ...,=& ...
- Qt入门(2)——使用Qt编写的Hello world
对于一个qt初学者来说,一步一步来直到作出一个hello world是最基础的入门. 从菜单:应用程序->编程中找到QtCreator
- Ubuntu 14.04 64位安装Android Studio 和 genymotion (上)
先说下,Ubuntu 上安装Android Studio真是一路坑阿,一路坑阿,加上天 朝 防火墙挡着,折腾了快一天才弄好阿 找了n多教程,md不是抄的就是转的,而且都没说清楚具体咋装阿,一个图一个 ...
- java,大数据批量插入、更新
public void exec(Connection conn){ try { conn.setAutoCommit(false); Long beginTime = System.currentT ...
- jquery $.each()用法
今天看到一个新的each玩法即each作为jquery的函数(平时用的大概都是用的each方法)使用: $.each([ 52, 97 ], function( index, value ) { al ...
- EF中主表和附表一起提交的话,如果主附表的主键外键已经设定。
EF中主表和附表一起提交的话,如果主附表的主键外键已经设定,如果新增同时新增主表和附表的记录,那么在EF同时提交时,不需要人为的设定附表的主表的主键值,EF会自动为附表添加外键值.
- [置顶] Extjs4 异步刷新书的情况下 保持树的展开状态
前言:首先我觉得搞IT不管你是菜鸟还是特种兵,最重要的品质就是分享知识,因为可能在你这,这点知识不算什么,可是对于像我这样的菜鸟来说,无疑就可能会从中得到一点启发,甚至更大!此段代码,是我在某个网站上 ...
- Android中AsyncTask的简单用法 .
在开发Android应用时必须遵守单线程模型的原则: Android UI操作并不是线程安全的并且这些操作必须在UI线程中执行.在单线程模型中始终要记住两条法则: 1. 不要阻塞UI线程 2. 确保只 ...