OpenJudge 2815 城堡问题 / Poj 1164 The Castle
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是一个城堡的地形图。请你编写一个程序,计算城堡一共有多少房间,最大的房间有多大。城堡被分割成mn(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的更多相关文章
- [POJ]1164 The Castle
//markdown复制进来一堆问题 还是链接方便点 POJ 1164 The Castle 首先想到用9个方格来表示一个房间,如此一来复杂许多,MLE代码如下: //Writer:GhostCai ...
- 百练oj 2815:城堡问题(dfs)
传送门: http://bailian.openjudge.cn/practice/2815 2815:城堡问题 查看 提交 统计 提示 提问 总时间限制: 1000ms 内存限制: 65536kB ...
- POJ 1164 城堡问题【DFS/位运算/种子填充法/染色法】
1 2 3 4 5 6 7 ############################# 1 # | # | # | | # #####---#####---#---#####---# 2 # # | ...
- POJ 1164:The Castle
The Castle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6677 Accepted: 3767 Descri ...
- 【OpenJudge 191】【POJ 1189】钉子和小球
http://noi.openjudge.cn/ch0405/191/ http://poj.org/problem?id=1189 一开始忘了\(2^{50}\)没超long long差点写高精度Q ...
- OpenJudge 2803 碎纸机 / Poj 1416 Shredding Company
1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms ...
- OpenJudge 2802 小游戏 / Poj 1101 The Game
1.链接地址: http://bailian.openjudge.cn/practice/2802 http://poj.org/problem?id=1101 2.题目: 总时间限制: 1000ms ...
- OpenJudge 2813 画家问题 / Poj 1681 Painter's Problem
1.链接地址: http://bailian.openjudge.cn/practice/2813 http://poj.org/problem?id=1681 2.题目: 总时间限制: 1000ms ...
- OpenJudge 2811 熄灯问题 / Poj 1222 EXTENDED LIGHTS OUT
1.链接地址: http://bailian.openjudge.cn/practice/2811 http://poj.org/problem?id=1222 2.题目: 总时间限制: 1000ms ...
随机推荐
- POJ1163 The Triangle: 倒三角形问题
经典的DP问题,DP思想也很直接: 直接贴代码: #include<iostream> #include<cstdio> #include<algorithm> # ...
- CentOS 6.4 安装 Transmission 2.76
1.安装Transmission 首先打开Transmission下载页:http://www.transmissionbt.com/download/ ,点击CentOS下载项,会跳转到一个叫&qu ...
- openstack 虚拟机流量
- 关于Redis的常识(推荐)
原文出处: https://github.com/springside/springside4/wiki/redis 版本:V3.0.3 2013-8-1 (@江南白衣版权所有,转载请保留出处) 1. ...
- map的基本操作函数及含义
map的基本操作函数: C++ Maps是一种关联式容器,包含“关键字/值”对 begin() 返回指向map头部的迭代器 clear() ...
- FFT(快速傅立叶算法 for java)
package com.test.test2; public class FFT { public static final int FFT_N_LOG = 10; // FFT_N_LOG ...
- XML与XHTML
什么是XML XML的基本格式 XML的定义文档 HTML5的文档定义 XHTML1.0的文档定义 XHTML1.0标记格式 12.1 什么是XML XML中文翻译为可扩展标记语言,顾名思义,它比HT ...
- iOS 极光推送
1.关于推送的几个证书.http://www.mobile-open.com/2016/931624.html 进入开发者中心:https://developer.apple.com/account/ ...
- lua 学习笔记(一)
lua 中的方法: 1. type("test"): 返回数据类型 2.#"zhangsan": 返回字符串的长度 3.string.gsub("字符 ...
- SqlServer数据库的一些方法的用途
一直分不清这三种方法的具体用法现在终于找齐了 ExecuteNonQuery方法和ExecuteScalar方法和ExecuteReader方法的区别 (1)ExecuteNonQuery():执行命 ...