題意:
  要確認畫面中有幾隻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. PHP+mysql统计排名第几位

    正在开发积分系统!其中有一项数据是显示用户积分排名?一下子想不到太好的办法! 最简的情况是统一某一字段的积分数据排名?比如积分字段,里面存的整数! 如何排名?或者说如何获得他在排序中的序列位次呢? s ...

  2. 0X0000124

     求教卡饭网友,都快疯掉了.      最近搞设计,电脑频发出现蓝屏,今晚都出现三次了,新装的win7 64位系统,都是安装的原版光驱.     错误代码基本上都是:0x00000124 (0x000 ...

  3. C语言整数按照二进制逆序,输出逆序后的整数值

    问题来源,今天早上和一舍友吃早餐的时候谈到的一个问题,将一个整数按照二进制逆序,然后输出逆序后的数值. 我们知道数值在内存中都是以二进制的形式存放的,假如我们是32位机,每8位为一个字节,int型在3 ...

  4. 在Activity的生命周期中,会被系统回调的方法

    onCreate(Bundle savedStatus):创建Activity时被回调.onStart():启动Activity时被回调.onRestart():重新启动Activity时被回调.on ...

  5. Qt on Android

    Qt on Android Episode 7(翻译) http://blog.csdn.net/foruok/article/details/46323129 Android基础整理之四大组件Act ...

  6. Android ListView嵌套Button,Button事件覆盖item事件解决办法

    方法就是修改item布局的xml文件: 在根布局里加上: android:descendantFocusability="blocksDescendants" 然后在按钮布局里加上 ...

  7. HDU_2024——判断字符串是否是c语言合法标识符

    Problem Description 输入一个字符串,判断其是否是C的合法标识符.   Input 输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是 ...

  8. HDU - 5156 Harry and Christmas tree

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=5156 题意 : 给一颗编号为1-n的以1为根的树, 已知有m个颜色的礼物分布在某些节点上(同一节点 ...

  9. Appnium+python实现手势密码为什么总是报错

    最近一直在尝试Appnium实现Android手机自动化测试,一直一直卡在一个点上,那就是手势密码,因为所测应用的手势密码使用的不是单个的imageview实现的手势密码解锁窗,所以只能靠坐标点来定位 ...

  10. appium 并发测试

    Android并发测试 Appium提供了在一台设备上启动多个Android会话的方案,而这个方案需要你输入不同的指令来启动多个Appium服务来实现. 启动多个Android会话的重要指令包括: - ...