1.链接地址:

http://bailian.openjudge.cn/practice/2815/

http://poj.org/problem?id=1164

2.题目:

总时间限制:
1000ms
内存限制:
65536kB
描述
     1   2   3   4   5   6   7  
#############################
1 # | # | # | | #
#####---#####---#---#####---#
2 # # | # # # # #
#---#####---#####---#####---#
3 # | | # # # # #
#---#########---#####---#---#
4 # # | | | | # #
#############################
(图 1) # = Wall
| = No wall
- = No wall

图1是一个城堡的地形图。请你编写一个程序,计算城堡一共有多少房间,最大的房间有多大。城堡被分割成mn(m≤50,n≤50)个方块,每个方块可以有0~4面墙。

输入
程序从标准输入设备读入数据。第一行是两个整数,分别是南北向、东西向的方块数。在接下来的输入行里,每个方块用一个数字(0≤p≤50)描
述。用一个数字表示方块周围的墙,1表示西墙,2表示北墙,4表示东墙,8表示南墙。每个方块用代表其周围墙的数字之和表示。城堡的内墙被计算两次,方块
(1,1)的南墙同时也是方块(2,1)的北墙。输入的数据保证城堡至少有两个房间。
输出
城堡的房间数、城堡中最大房间所包括的方块数。结果显示在标准输出设备上。
样例输入
4
7
11 6 11 6 3 10 6
7 9 6 13 5 15 5
1 10 12 7 13 7 5
13 11 10 8 10 12 13
样例输出
5
9
来源
1164

3.思路:

深搜

4.代码:

 #include <iostream>
#include <cstdio> using namespace std; int idx_x[] = {-,,,};
int idx_y[] = {,-,,}; int m,n; int f(int **arr,int i,int j)
{
//cout << "f(" << i << "," << j << ")" << endl; /*for(int y = 0; y < m; ++y)
{
for(int x = 0; x < n; ++x)
{
cout << arr[y][x] << " ";
}
cout << endl;
}*/ if(i < || i >= m || j < || j >= n || arr[i][j] == -) return ;
int value = arr[i][j]; int res = ;
int k;
arr[i][j] = -;
for(k = ; k < ; ++k)
{
if(value % == ) res += f(arr,i + idx_y[k],j + idx_x[k]);
value /= ;
}
return res;
} int main()
{
//freopen("C://input.txt","r",stdin); int i,j; //int m,n;
cin >> m >> n; int **arr = new int*[m];
for(i = ; i < m; ++i) arr[i] = new int[n]; for(i = ; i < m; ++i)
{
for(j = ; j < n; ++j)
{
cin >> arr[i][j];
}
} int count = ;
int max = ;
int num;
for(i = ; i < m; ++i)
{
for(j = ; j < n; ++j)
{
if(arr[i][j] != -)
{
num = f(arr,i,j);
//cout << "num=" << num << endl;
if(max < num) max = num;
++count;
}
}
}
cout << count << endl;
cout << max << endl; for(i = ; i < m; ++i) delete [] arr[i];
delete [] arr; return ;
}

OpenJudge 2815 城堡问题 / Poj 1164 The Castle的更多相关文章

  1. [POJ]1164 The Castle

    //markdown复制进来一堆问题 还是链接方便点 POJ 1164 The Castle 首先想到用9个方格来表示一个房间,如此一来复杂许多,MLE代码如下: //Writer:GhostCai ...

  2. 百练oj 2815:城堡问题(dfs)

    传送门: http://bailian.openjudge.cn/practice/2815 2815:城堡问题 查看 提交 统计 提示 提问 总时间限制: 1000ms 内存限制: 65536kB ...

  3. POJ 1164 城堡问题【DFS/位运算/种子填充法/染色法】

    1 2 3 4 5 6 7 ############################# 1 # | # | # | | # #####---#####---#---#####---# 2 # # | ...

  4. POJ 1164:The Castle

    The Castle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6677   Accepted: 3767 Descri ...

  5. 【OpenJudge 191】【POJ 1189】钉子和小球

    http://noi.openjudge.cn/ch0405/191/ http://poj.org/problem?id=1189 一开始忘了\(2^{50}\)没超long long差点写高精度Q ...

  6. OpenJudge 2803 碎纸机 / Poj 1416 Shredding Company

    1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms ...

  7. OpenJudge 2802 小游戏 / Poj 1101 The Game

    1.链接地址: http://bailian.openjudge.cn/practice/2802 http://poj.org/problem?id=1101 2.题目: 总时间限制: 1000ms ...

  8. OpenJudge 2813 画家问题 / Poj 1681 Painter's Problem

    1.链接地址: http://bailian.openjudge.cn/practice/2813 http://poj.org/problem?id=1681 2.题目: 总时间限制: 1000ms ...

  9. OpenJudge 2811 熄灯问题 / Poj 1222 EXTENDED LIGHTS OUT

    1.链接地址: http://bailian.openjudge.cn/practice/2811 http://poj.org/problem?id=1222 2.题目: 总时间限制: 1000ms ...

随机推荐

  1. iOS 设置connect超时

    NSLock *theLock; [theLock lock]; int fd, error; struct sockaddr_in addr; ))<) { cout<<" ...

  2. HTTP 和 SOAP 标头 来传递用户名密码 验证webservice用户认证

    支持自定义的 HTTP 和 SOAP 标头 注意:本主题中的内容适用于 Microsoft Office SharePoint Server 2007 SP1. 对于 Web 服务,您可以使用 HTT ...

  3. DevExpress的GridControl控件更新數據問題解決辦法

    開發WPF程序時,使用Devexpress的GridControl控件用ItemSource綁定數據,在頁面進行編輯時,當屬性繼承INotifyPropertyChanged接口時會同步更新後臺數據. ...

  4. How to change pager CSS in CGridView CListView in Yii

    类手册: http://www.yiiframework.com/doc/api/1.1/CLinkPager 其它参考: http://capstone3.blogspot.com/2012/06/ ...

  5. hdu 3996 (最大权闭合图)

    题意:有n个区域布局,每个区域有一些金矿,挖开金矿需要一定的费用,可以得到一定的利润,要想挖开一个金矿,必须挖开所有在这个金矿上边的金矿,求最大利益,给的数据价值太大,用64位. 分析:如果一个金矿可 ...

  6. js关键字

    这已经是我第二次遇到这个问题了..关于关键字,用来做函数的命名,,,在高清上没问题,标清上秒死...页面都出不来...wtf...做个记录.. js关键字http://www.itxueyuan.or ...

  7. 【转】基于RMAN实现坏块介质恢复(blockrecover)

    本文转自:乐沙弥的世界 对于物理损坏的数据块,我们可以通过RMAN块介质恢复(BLOCK MEDIA RECOVERY)功能来完成受损块的恢复,而不需要恢复整个数据库或所有文件来修复这些少量受损的数据 ...

  8. NSUInteger和NSInteger和int

    int和NSInteger其实是差不多的,但更推荐使用NSInteger,因为使用NSInteger,这样就不用考虑设备是32位还是64位了. NSUInteger是无符号的,即没有负数,NSInte ...

  9. iOS开发多线程篇---atomic nonatomic区别

    摘要 atomic和nonatomic区别用来决定编译器生成的getter和setter是否为原子操 作.atomic提供多线程安全,是描述该变量是否支持多线程的同步访问,如果选择了atomic 那么 ...

  10. 【Heritrix基础教程之1】在Eclipse中配置Heritrix

    一.新建项目并将Heritrix源代码导入 1.下载heritrix-1.14.4-src.zip和heritrix-1.14.4.zip两个压缩包,并解压,以后分别简称SRC包和ZIP包: 2.在E ...