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

    public class Solution { public static void main(String[] args) { System.out.println("π = " ...

  2. Fibonacci数列小程序

    Fibonacci数列小程序 问题分析:Fibonacci数列特征是前两项数均为1,从第三项起,前两项的和为第三项的数的数值用公式归纳起来为:f1=f2=1.f1=f1+f2.f2=f1+f2. 程序 ...

  3. ZOJ3471--Most Powerful(状压DP)

    有n(n<10)个小球,每两个碰撞有其中一个会消失,并产生一定能量.求产生最大能量. 有了正确思路题目比较简单,我的思路果然是歪的... 我的思路是dp[i][j]表示i这个状态剩下第j个小球, ...

  4. MSSQL数字时间(timestamp)转换为DATETIME

    很简单: , CAST('1970-01-01 00:00:00' AS datetime))

  5. 用C语言实现有限状态自动机FSM

    摘要:状态机模式是一种行为模式,在<设计模式>这本书中对其有详细的描述,通过多态实现不同状态的调转行为的确是一种很好的方法,只可惜在嵌入式环境下,有时只能写纯C代码,并且还需要考虑代码的重 ...

  6. hdu4433 locker

    暴力dp.. dp[i][j][k] 表示 前i位完全匹配 j 表示i+1位 k表示i+2位 枚举j k #include<iostream> #include<cstdio> ...

  7. linux安装svn服务器(yum方式)

    1.查看yum是否安装         在终端中输入yum即可如果已经安装,会显示yum的参数         如果没有安装,会提示yum未安装或无效命令…… 2.安装svnyum -y instal ...

  8. 在SCVMM2012R2中删除失去联系的VM GateWay

    当VM Gateway失去联系,无法使用,直接删除GW,或者在VM Network中删除GW连接,均会出现如下错误提示: 错误(21426)对配置提供程序 4ee559f1-f479-480c-945 ...

  9. java基础之synchronized使用方法

    首先.參考文章:http://www.cnblogs.com/devinzhang/archive/2011/12/14/2287675.html PS:參考文章非常长,但内容非常丰富,若是刚開始学习 ...

  10. TCP/IP 中的二进制反码求和算法

    对于这个算法,很多书上只是说一下思路,没有具体的实现.我在这里举个例子吧 以4bit(计算方便一点,和16bit是一样的)做检验和来验证. 建设原始数据为 1100 , 1010 , 0000(校验位 ...