題意:
  要確認畫面中有幾隻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. REDIS学习(1)环境搭建

    1.下载 稳定版本的.tar.gz 包,解压到/usr/local/src/. 2 .cd 到文件夹下,不需要 configure 直接 make编译 ,成功之后,cd /usr/local/redi ...

  2. 汉诺塔 Hanoi Tower

    电影<猩球崛起>刚开始的时候,年轻的Caesar在玩一种很有意思的游戏,就是汉诺塔...... 汉诺塔源自一个古老的印度传说:在世界的中心贝拿勒斯的圣庙里,一块黄铜板上插着三支宝石针.印度 ...

  3. Autofact 的使用

    资料: http://www.cnblogs.com/linhan/p/4298971.html --其他博友 http://autofac.org/# --官网 http://efmvc.codep ...

  4. Flume笔记--source端监听目录,sink端上传到HDFS

    官方文档参数解释:http://flume.apache.org/FlumeUserGuide.html#hdfs-sink 需要注意:文件格式,fileType=DataStream 默认为Sequ ...

  5. js中给函数传参函数时,函数加括号与不加括号的区别

    <!doctype html><html><head><script> function show() { alert("123") ...

  6. oracle 数据库连接的四种方式

    Oracle Thin JDBC Driver驱动程序包名:ojdbc14.jar.ojdbc6.jar驱动程序类名: oracle.jdbc.driver.OracleDriverJDBC URL: ...

  7. MD5 加密 代码

    /*! 获取MD5 加密串 */ +(NSString *)getAuthorization:(NSString *)type Date:(NSDate *)date UserSecret:(NSSt ...

  8. android数据保存

    永久保存数据的方法:1.Shared Preferences 以键值对的形式存储基本数据类型( booleans, floats, ints, longs, and strings),存储的数据在限制 ...

  9. rsyslog 只读取变化的日志

    <pre name="code" class="html">input(type="imfile" File="/us ...

  10. Best Time to Buy and Sell Stock IV 解答

    Question Say you have an array for which the ith element is the price of a given stock on day i. Des ...