題意:
  要確認畫面中有幾隻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的更多相关文章

  1. UVA352 The Seasonal War

    本文为UserUnknown原创 题目本身不难理解,就是深搜(或广搜,有可能以后会加在这里). 但是洛谷的题目中没有截到输入输出的格式,下面是我从UVA复制下来的样例: Sample input 6 ...

  2. 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 ...

  3. 使用maven多模块来构建系统时,spring初始化报错的问题

    最近在实验maven结构的maven工程时,碰到一个问题,springbean总是初始化失败: Related cause: org.springframework.beans.factory.Uns ...

  4. UVa 11729 - Commando War(贪心)

    "Waiting for orders we held in the wood, word from the front never came By evening the sound of ...

  5. Uva 11729 Commando War (简单贪心)

    Uva 11729  Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...

  6. 贪心 UVA 11729 Commando War

    题目传送门 /* 贪心:按照执行时间长的优先来排序 */ #include <cstdio> #include <algorithm> #include <iostrea ...

  7. cogs 1446. [Commando War,Uva 11729]突击战

    1446. [Commando War,Uva 11729]突击战 ★   输入文件:commando.in   输出文件:commando.out   简单对比时间限制:1 s   内存限制:64 ...

  8. [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 ...

  9. 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 ...

随机推荐

  1. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. (关于jdbc)

    The last packet sent successfully to the server was milliseconds ago. The driver has not received an ...

  2. 文成小盆友python-num17 - django基础

    一.首先了解web应用的本质 对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. 下面利用socket实现一个简单的web框架: #!/usr/b ...

  3. SVM及其对偶

    引自 http://my.oschina.net/wangguolongnk/blog/111349 1. 支持向量机的目的是什么? 对于用于分类的支持向量机来说,给定一个包含正例和反例(正样本点和负 ...

  4. 使用activeMQ实现jms

    一:jms介绍         jms说白了就是java message service,是J2EE规范的一部分,跟jdbc差不多,sun只提供了接口,由各个厂商(provider)来进行具体的实现, ...

  5. 转: linux下错误的捕获:errno和strerror的使用

    经常在调用linux 系统api 的时候会出现一些错误,比方说使用open() write() creat()之类的函数有些时候会返回-1,也就是调用失败,这个时候往往需要知道失败的原因.这个时候使用 ...

  6. word 生成目录

    生成目录: (1)Ctrl+End,到达文档的最后一页: (2)"插入"菜单--引用--索引和目录(此时出现索引和目录对话框): (3)单击"目录"选项卡 a. ...

  7. C++中的string类(2)

    相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯 ...

  8. hdu-1598

    思路: 首先如果想到了Kruskal算法,那么下一步我们可能马上会想:那我们就从头开始写这个算法吧.然后一写就很容易发现一个问题——如果按照正常的Kruskal算法来做,那么start到end的舒适度 ...

  9. HDU 3262 Seat taking up is tough (模拟搜索)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3262 题意:教室有n*m个座位,每个座位有一个舒适值,有K个学生在不同时间段进来,要占t个座位,必须是连 ...

  10. Spring MVC 前后台数据交互

    本文是转载文章,感觉比较好,如有侵权,请联系本人,我将及时删除. 原文网址地址:<Spring MVC 前后台数据交互> 1.服务端数据到客户端 (1)返回页面,Controller中方法 ...