HDU 6113 度度熊的01世界
度度熊的01世界
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1276 Accepted Submission(s): 466
现在给你一个n*m的图像,你需要分辨他究竟是0,还是1,或者两者均不是。
图像0的定义:存在1字符且1字符只能是由一个连通块组成,存在且仅存在一个由0字符组成的连通块完全被1所包围。
图像1的定义:存在1字符且1字符只能是由一个连通块组成,不存在任何0字符组成的连通块被1所完全包围。
连通的含义是,只要连续两个方块有公共边,就看做是连通。
完全包围的意思是,该连通块不与边界相接触。
每组测试数据包含:
第一行两个整数n,m表示图像的长与宽。
接下来n行m列将会是只有01组成的字符画。
满足1<=n,m<=100
00000000000000000000000000000000
00000000000111111110000000000000
00000000001111111111100000000000
00000000001111111111110000000000
00000000011111111111111000000000
00000000011111100011111000000000
00000000111110000001111000000000
00000000111110000001111100000000
00000000111110000000111110000000
00000001111110000000111110000000
00000001111110000000011111000000
00000001111110000000001111000000
00000001111110000000001111100000
00000001111100000000001111000000
00000001111000000000001111000000
00000001111000000000001111000000
00000001111000000000000111000000
00000000111100000000000111000000
00000000111100000000000111000000
00000000111100000000000111000000
00000001111000000000011110000000
00000001111000000000011110000000
00000000111000000000011110000000
00000000111110000011111110000000
00000000111110001111111100000000
00000000111111111111111000000000
00000000011111111111111000000000
00000000111111111111100000000000
00000000011111111111000000000000
00000000001111111000000000000000
00000000001111100000000000000000
00000000000000000000000000000000
32 32
00000000000000000000000000000000
00000000000000001111110000000000
00000000000000001111111000000000
00000000000000011111111000000000
00000000000000111111111000000000
00000000000000011111111000000000
00000000000000011111111000000000
00000000000000111111110000000000
00000000000000111111100000000000
00000000000001111111100000000000
00000000000001111111110000000000
00000000000001111111110000000000
00000000000001111111100000000000
00000000000011111110000000000000
00000000011111111110000000000000
00000001111111111111000000000000
00000011111111111111000000000000
00000011111111111111000000000000
00000011111111111110000000000000
00000000001111111111000000000000
00000000000000111111000000000000
00000000000001111111000000000000
00000000000111111110000000000000
00000000000011111111000000000000
00000000000011111111000000000000
00000000000011111111100000000000
00000000000011111111100000000000
00000000000000111111110000000000
00000000000000001111111111000000
00000000000000001111111111000000
00000000000000000111111111000000
00000000000000000000000000000000
3 3
101
101
011
1
-1
/*
* @Author: lyuc
* @Date: 2017-08-12 14:12:48
* @Last Modified by: lyuc
* @Last Modified time: 2017-08-13 21:50:49
*/ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> #define LL long long
#define INF 0x3f3f3f3f
#define MAXN 105 using namespace std; char mapn[MAXN][MAXN];
int n,m;
int res1;
int res2;
int dir[][]={,,-,,,,,-};
bool vis[MAXN][MAXN]; bool ok1(int x,int y){
if(x<||x>=n||y<||y>=m||vis[x][y]==true||mapn[x][y]=='')
return false;
return true;
} void dfs1(int x,int y){
vis[x][y]=true;
for(int i=;i<;i++){
int fx=x+dir[i][];
int fy=y+dir[i][];
if(ok1(fx,fy)==false) continue;
dfs1(fx,fy);
}
} bool ok2(int x,int y){
if(x<||x>n||y<||y>m||vis[x][y]==true||mapn[x][y]=='')
return false;
return true;
} void dfs2(int x,int y){
vis[x][y]=true;
for(int i=;i<;i++){
int fx=x+dir[i][];
int fy=y+dir[i][];
if(ok2(fx,fy)==false) continue;
dfs2(fx,fy);
}
} void init(){
res1=;
res2=;
memset(vis,false,sizeof vis);
} int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(scanf("%d%d",&n,&m)!=EOF){
init();
for(int i=;i<=n;i++){
scanf("%s",mapn[i]+);
}
n++;
m++;
for(int i=;i<=n;i++){
mapn[i][]='';
mapn[i][m]='';
} for(int i=;i<=m;i++){
mapn[][i]='';
mapn[n][i]='';
} //找1联通块
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(mapn[i][j]==''){
if(vis[i][j]==true) continue;
res1++;
dfs1(i,j);
}
}
} //找0联通快
memset(vis,false,sizeof vis);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(mapn[i][j]==''){
if(vis[i][j]==true) continue;
res2++;
dfs2(i,j);
}
}
} if(res1==&&res2==){
puts("");
}else if(res1==&&res2==){
puts("");
}else{
puts("-1");
}
}
return ;
}
HDU 6113 度度熊的01世界的更多相关文章
- HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))
度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 【判连通】HDU 6113 度度熊的01世界
http://acm.hdu.edu.cn/showproblem.php?pid=6113 [题意] 度度熊是一个喜欢计算机的孩子,在计算机的世界中,所有事物实际上都只由0和1组成. 现在给你一个n ...
- 2017"百度之星"程序设计大赛 - 初赛(A) [ hdu 6108 小C的倍数问题 ] [ hdu 6109 数据分割 ] [ hdu 6110 路径交 ] [ hdu 6112 今夕何夕 ] [ hdu 6113 度度熊的01世界 ]
这套题体验极差. PROBLEM 1001 - 小C的倍数问题 题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6108 (2017"百度之星 ...
- HDU 6113 度度熊的01世界【DFS/Flood Fill】
度度熊的01世界 Accepts: 967 Submissions: 3064 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- hdu 6113 度度熊的01世界(结构体的赋值问题)
题目大意: 输入n*m的字符串矩形,判断里面的图形是1还是0,还是什么都不是 注意:结构体中放赋值函数,结构体仍旧能定义的写法 #include <iostream> #include&l ...
- HDU - 6113 2017百度之星初赛A 度度熊的01世界
度度熊的01世界 Accepts: 967 Submissions: 3064 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327 ...
- 【2017"百度之星"程序设计大赛 - 初赛(A)】度度熊的01世界
[链接]http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=775&pid=1006 [题意] 在这里写题意 [题 ...
- 百度之星2017初赛A-1006-度度熊的01世界
度度熊的01世界 Accepts: 967 Submissions: 3064 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- HDU 6118 度度熊的交易计划 【最小费用最大流】 (2017"百度之星"程序设计大赛 - 初赛(B))
度度熊的交易计划 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- 深度学习网络层之 Batch Normalization
Batch Normalization Ioffe 和 Szegedy 在2015年<Batch Normalization: Accelerating Deep Network Trainin ...
- 解决linux AMR转MP3出现转码成功却无法播放的问题
根据帖子:http://blog.csdn.net/z313731418/article/details/50218341 的提示,在linux安装ffmpeg,确实在linux下使用命令可以将am ...
- HTML5基本标签的使用
第一次写这种东西,肯定存在许多不足之处,还望大家多多担待,我会继续加油的!我也是一名HTML5的初学者,只是将这几周在课堂上所听到的东西分享给大家. 下面给大家介绍一下H5! 一.<!DOCTY ...
- AngularJS中的DOM与事件
前 言 AngularJS中的DOM与事件 AngularJS 为 HTML DOM 元素的属性提供了绑定应用数据的指令. ng-disabled="true/false" ...
- Opengl4.5 中文手册—C
索引 A B C D E F G H I J K L M N O P Q ...
- js 操作数组(过滤对应数据)
过滤掉相应数据 var fileList = { "85968439868a92": [{name: 'food.jpeg'}, {name: 'ood.jpeg'}], &quo ...
- 程序员的自我修养九Windows下的动态链接
9.1 DLL简介 DLL即动态链接库的缩写,它相对于Linux下的共享对象. Windows下的DLL文件和EXE文件实际上是一个概念,它们都是有PE格式的二进制文件. 微软希望通过DLL机制加强软 ...
- Minutes和TotalMinutes的区别
今天测试提了一个BUG,说是消息提醒的时机不对,设置的提前2小时,还没到就提醒了. 看了下代码 (m.ExpectReceiveTime - DateTime.Now).Minutes < (p ...
- An Introduction to Variational Methods (5.2)
我们现在已经得到了关于潜在变量Z的优化分布的表达形式: 其中: 所以现在我们可以得到Z的期望: 另外对于Z还值得一提的是,我们从其优化分布的表达式中可以看出,各个Z的组成部分之间还是相互耦 ...
- DOM中的parentNode总结
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...