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 ...
随机推荐
- BigDecimal的加减乘除及比较大小
import java.math.BigDecimal; import static java.lang.System.out; public class BaseClass { public sta ...
- Https系列之三:让服务器同时支持http、https,基于spring boot
Https系列会在下面几篇文章中分别作介绍: 一:https的简单介绍及SSL证书的生成二:https的SSL证书在服务器端的部署,基于tomcat,spring boot三:让服务器同时支持http ...
- CentOS6.x服务器OpenSSH平滑7.3p版本——拒绝服务器漏洞攻击
对于新安装的Linux服务器,默认OpenSSH及OpenSSL都不是最新的,需要进行升级以拒绝服务器漏洞攻击.本次介绍的是升级生产环境下CentOS6.x系列服务器平滑升级OpenSSL及OpenS ...
- BZOJ-1050-[HAOI2006]旅行comf(并查集)
Description 给你一个无向图,N(N<=500)个顶点, M(M<=5000)条边,每条边有一个权值Vi(Vi<30000).给你两个顶点S和T,求 一条路径,使得路径上最 ...
- PLT文件 和 DXF文件
PLT: CAM/CAD类似软件处理的图像文件的文件格式 DXF: AutoCAD(Drawing Interchange Format或者Drawing Exchange Format) 绘图交换文 ...
- crontab的两大坑:百分号和环境变量
今天想给服务器加个自动备份mysql数据库的功能(别怪我这么久才加,阿里云每天全盘备份的,不怕丢数据库),本以为只要5分钟就能搞定的,结果入了两个大坑. 我的crontab是这样写的: * * * m ...
- 【JVM命令系列】jstack
jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,如果是在64位机器上,需要指定选项"-J-d64",Windows的jstack使 ...
- 机器学习实战K-近邻算法
今天开始学习机器学习,第一章是K-近邻算法,有不对的地方请指正 大概总结一下近邻算法写分类器步骤: 1. 计算测试数据与已知数据的特征值的距离,离得越近越相似 2. 取距离最近的K个已知数据的所属分类 ...
- python的urlparse
urlparse主要是URL的分解和拼接,分析出URL中的各项参数,可以被其他的URL使用. 主要的函数有: 1.urlparse 将URL分解为6个片段,返回一个元组,包括协议.基地址.相对地址等等 ...
- Oracle 之——子查询 DDL DML 集合 及其他数据对象
Oracle 学习笔记(二) 知识概要: 1.子查询 2.集合操作 3.DML语句操作 4.其他数据库对象 1.子查询 查询工资比SCOTT高的员工信息 1 select * 2 from emp ...