题意,给你迷宫算出其中个封闭空间的个数,以及求出所有封闭的空间的最大步长,但是给你的迷宫式“/”,“\”来标记的所以需要将每个格子分开来3*3的格子来算,

一开始按照2*2来算,2*2有临界情况不好算(233333)……

格式需要额外空一行……

题很简单,就是dfs走出边界说明不是封闭的……

不过就这样了……还是太弱了……

话说,今天又颓了一天……

233333333

代码……

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <malloc.h>
#include <queue>
#include <map> using namespace std;
const int INF = 0xffffff;
const double Pi = * atan();
const int Maxn = + ;
//int dir2[8][2] = {{-1,0},{0,-1},{-1,1},{1,-1},{-1,-1},{1,0},{0,1},{1,1}};
int dr[] = {,,-,,-,,-,};
int dc[] = {,,,-,,-,-,}; bool graph[][];
int w,h;
int num;
bool flag; void dfs(int r,int c){
if(r < || c < || r > *h- || c > *w- ){
flag = ;
return;
}
if(graph[r][c])
return;
graph[r][c] = ;
num++;
for(int i = ;i < ;i++){
int xx = r + dr[i];
int yy = c + dc[i];
dfs(xx,yy);
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("inpt.txt","r",stdin);
#endif
int cas = ;
while(cin >> w >> h){
if(!w && !h)
break;
cout << "Maze #" << ++cas << ":" << endl;
if(!w || !h){
cout << "There are no cycles." << endl << endl;
continue;
}
char str[];
memset(graph,,sizeof(graph));
for(int i = ;i < h;i++){
cin >> str;
for(int j = ;j < w;j++){
if(str[j] == '\\'){
graph[*i][j*] = graph[*i+][*j+] = graph[*i+][*j+] = ;
}
else if(str[j] == '/'){
graph[*i][j*+] = graph[*i+][*j+] = graph[*i+][*j] = ;
}
}
}
/* for(int i = 0;i < 3*h ;i++){
for(int j = 0;j < 3*w;j++)
cout << graph[i][j];
cout << endl;
}*/
int cnt = ;
int road = -;
for(int i = ;i < *h;i++){
for(int j = ;j < * w;j++){
if(!graph[i][j]){
flag = ;
num = ;
dfs(i,j);
if(flag)
continue;
cnt++;
if(num > road)
road = num;
}
}
}
if(cnt == )
cout << "There are no cycles." << endl;
else{
cout << cnt << " Cycles; the longest has length " << road/ << "." << endl;
}
cout << endl;
}
return ;
}

测试用例:

\//\\/
\///\/
//\\/\
\/\/// ///
\//
\\\ /\/\/
\/\/\
/\/\/
/\/\/
\/\/\ //\\
//\\
\\//
\\// /\/\/\
\//\\/
///\\\
\\\///
/\\//\
\/\/\/ /\/\/\
\\/\//
//\/\\
\/\/\/ /\/\/\
\\/\//
//\/\/
\/\/\/ \\\//\/\\/////\//\\\\\\/\//\\\\//\//////\\\/\//\/\\/\\/\/\//\/\/\\\/\/\ \//\
//\\\/\/\\\//\/\\\/\/\/\\\/\/\/\\//\/\\\/\\/\/\//\\/\///////\//\/\\///\/ \\/
/\\//\///\\\\/////\//\/\///\\\\/\//\/\\/\\\\\\/\////\\\\//\\////\/\\\/\/ \\\
\\\//\\\/\\/\/\/\\/\/\\\\/\\\\//\\\/\/\\/\\\\\\\\/\\/\////\\//\\\//\/ \///\\
/\\//\/\/\/\\\//\/\/\\/\\/\\\\\//\\/\\///\\/\\\///\\//\\///\//////\\//\/ \\/
\\\\\//\\\\/\\/\///\\/\/\\/\///\////\/\\\/\\/\/\/\\\/\\\\/////\\\\//\\\ \//\
\///\/\/\\//\\\\/\\\\//\/\//\\/\///\\\\\\\/\\\\/\/\\\//\\/\\//\///\/\\ \//\/
\\/\\//////\//\\/\/\\\\\\//\\\\//\//\//\/\/\/\/\\//\\/\///\//\\\\\/\\//\ \\\
//\\/\//\\//\//\//\/\\///\\/\/\////\\/\\///\////\/\\///\\/\///\\\\//\\/ \///
\//\////\///\\\\\\\///\//\/\///\\/\/\\\\///\\\/\\\///\\\/\\//\\/\\/\//\/ \\\
/\\//\\///\\\\\\///\////\///\/\/\\\//\\/\\/\////\/\\/\/\////\/\/\\/\/\/ \/\/
/\/\\\\\/\\/\/\\/\\///\\//\//\/\//\//\////////\////\\/\\\\\\\///\\////\ \/\\
/\//\\/\\\/\\/\//\\\\\/\\\////\//\\/\\\\\\\/////\\\////\/\\//\/\\\\\/\// \\\
\/\\/\//\\\//\/\\\/\\///\\\\\\\\/\\\//\\\///\\\/\\\/\\\\\\/\/\\/\/\/\/\/ \/\
//\\//\\/\\//\\\\///\\\\\\\/\\///\\//\///\//////\/\//\/\\\\/\\/\//\\/\/ \///
\\/\/\//\/\//\\///\\\\\/\///////////\///\\/\/\//\/\///\/\\\/\/\\/\\\\\/\ \/\
///\\\\///\/\//\\\\\/\/\\\\///\\\/\\\\\\\\\\///\\\\\/\///\\/\/\///\\\\\ \/\/
\//\\\\\/\////\\\/\\\/\\\\/\/\//\////\\//\//////\/\//\\/\///\/\/\\///\ \///\
/\\/\\\\\\\\\\\\//\\\///\///\\/\\\\///\////\\///\//\/////\\\//\//\\/\\\/ \\/
//\/////\\/\\\\/\\\/\\//\\\\\//////\//\\/\////\///\\\\//\////\/\/\/\/// \//\
//\\\\\/\//\//\\\\\\///\\\/\/\////\/\/\\\\\/\///\/\\\///\\//\\\/\/\\//\/ \/\
\\/\\\/\\//\///\\//\\\\\\/\/\\///////\/\//\\\/\\////\\\\\/\\\/\\/\/\//// \\\
/\\//\\\\/\/\/\\/\\/\/\\///\////\\\//\/\\//\\/\///\/\\//\\/\////\//\\/\\ \\\
\\/\//\\///\/\/\//\//\\\\\//\/\\/\/\//\\///////////////\/\\/\\\/\\\\/\\/ \//
//\//\////\///\/\/\/\///\\//\\/\\//\//\\/\//\/\/\//\\\\\\///\/\\\\\\//\/ \\/
\\//\//\\//\\/\\\\/\\\\\/\\/\\//\/\\\/\//\\\///\\/\\\/\\//\\/\\/\///\/\\ \/\
/\//\//\/\\\/\\///\\\/\\/\/\\///\\\\///\//\/\\\\///\\\\/\\/\\\/\///\/\\ \//\
\//\\//\///\/\/\\\\/\\/\\\\\\////\\\\/\\\///\\/\\/\\\\\\/\//\\/\\//\/\// \//
//\\\/\///\/\\\\\/\\//\////\\//\\//\/\//\\/////\\\/\\\/////\\//\/\/\\\/\ \\/
//\/\\/////\\\\\\////\\\\/\\/\//\/\\//\\\//\/\///\\/\\\\//\///\//\///\/\ \\/
//////\/\///\\\///////\\\/\/\\//\\\//\\\\\\/////\//\/\/////\\//\\/\/\/\/ \/\
/\/\///\\//\///\\\\\/\\/\\////\/\/\/\//\//\\///\///\\/\/\/\/\\\\//\/\\ \//\\
\\/\/\//\\\//\\//\///\\\/\\//\///\/\////\/\/\\\/\//\\\///\/\/\\/\///\\ \///\
\//\//\\/\///\/\/\\/\/\\\\///\\/////\/\\///////////\/\\\\/\\\\\/\///// \///\
/\///\\\////\\\\/\/\\\///\//\\\\\\/\///\\//\//////\\/\\/\\\/\\\\\\/\//\ \///
\/\////\/\///\\///\///\\\/\\\/\/\\/\/\\\\/\\\\/////\\\\////\///\\\/\///\ \//
/\\//////\/\////\/\///\\\/\///\\\\//////\\/////\/\////\\/\/////\\//\//\ \/\\
/\/\/\\///\\\\///\\//\/\/\/\////\//\//\\/\//\//\/\////\/\////\\/\//\\\\ \/\\
/\\\\\/\/\/\/\\\/\\\//\\/\\/////\/\/\\//\\/\/\//\/\/\\////\//\//\/\\/\\ \/\\
\\/\\\/\/\\\/\\\////////\\//\\/\///\/\/\////\//\\/\\\\\\\\//\\\\/\\\\\\/ \//
//\/\/\//\/\/\/\\/\/\\/\\\/\//\//////\//\\\\\\\///\\/\//////\\/\\////\\\ \/\
////\/\\/\\///\\\\///\/\//\\/\/\//\\/\//\/\\/\//////\//\/////\/\\\/\\/\ \/\\
//\/\//\\/\//\/\\\\//\\//\/\//\\\///\//\\\///\\\\/\\//\\\\//\//\\\\/\\/\ \/\
/\\\\////\\//\\\/\\\\\///\\\\\/\\\\\///\\\/\//\\\\//\\/\///////\/\//\ \/////
//\\\\\\/\/\\/\\\/\/\\\\//\//\\/\\\\/\/\\\/\//\/\/\/\\\////\/\\///\/\/ \//\\
///\/\///\\/\\/\/\/\///\//\///\////\\//\\/\/\//\\\////\////\////\\\\/\ \///\
\\\//\//\\\\\//\//\\////\//\\///\/\/\\\/\//\/\\\//\\\/\\\\//\\/\//\// \/////
\/\\\\\\\\\/\//\\\/\\\\\/\\\/\\/\/\/\/\/\\\\/////\//\\\/\\\\\\/\\/\\\\\ \/\/
//\/////\/\/\\///////\\//\\\\\\////\\////\/\//\///\\\\//\/\\\\\\\//\/\\\ \//
\\/\/\\\//\//\\\//\/\\\\/\\/\\///////\///\\/\\\/\///\\///////\\\/\\\\\\\ \//
\\//\/\//\\//\\//\\\\\\/\\\/\/\\/\\\\\//\\\\/\/\//\//\///\\\\/\\//\////\ \\/
/\\/\/\//\//\\\/\//\\/\/\\\\\\/\\//\/\\/\\///\/\\\//\\//\\/\\\\////\//\ \///
///\\\\/\/\\\\/\\///\\\//\/\//\//\\\//\\///\////\/\//\\\///\//////\\\\\/ \\\
/\\\/\////\///\\\\///\\\\/\/\\\\\/\//\\/\\//////\\\\\/\\/\//\///\\/\\\/\ \\/
\\\//\\\\\\/\\\//\\//\//\/\\//\\\////\\/\/\/\\/\\\///\///\/\\/\\\/\/\// \//\
\/\\\/////\\////\////\\\//\\/\\/\/\\\/\/\/\/\/\///\////\\\///\\//\/\/\// \\/
//\/\///\\//\/\\////\///\\/\////\/\///\\\//\//////\\\\\/\\/\\\/\\/\\\\\/ \//
//\/\//\\/\///\\/\\///\///\//\/\\//////\//\\\\/\///////\\\////\\/\//\// \//\
//\\\/\\/\/\/\\/\/\/\//\\\/\//\//\\\\/\//\\\\\\/\////\\\/\\\/\\//\//\/\\ \//
\/\\/\\\\/\//\/\\/\/\\\//\\\\/\//\\/\/\\\\\///\\\\\/\\\/\/\\/\\\\\\/\/\/ \/\
\\///\/\/\///\/\\\\\/\\/\//////\/\///\/\/\\/\/\\//\/\//\//\\\\/\\\\///\/ \/\
/\/\/\\\\/\///\\/\/\\/\/\\\\/\/\/\//\\\\\/////\//\\//\\/\\\///\\\//\\\/\ \\\
/\\\\//\///\//\/////\/\\/////\/\/\\\\/\\//\//\\\\\/\////\\\\/\\/\////\\ \//\
\/\/\///\//\\\\\/\\\\\///\//\\////\\\\\/\/////\\\/\\//\\\///\///\//\///\ \\/
\///\\\////\/\\/\/\\//\/\////\\\\/\\\/\\/\\\\\\\//\\////\/\\\\\\///\//\/ \//
/\/\//\///\//////\\\/\\/\///\/\/\//\\/\/\\////\\\\\\/\/\\\//\/\\/\\\/\// \\\
/\\//\\\//////\\/\\///\/\/\\/\/\////\\/\\\/\\//////////\///\/\\/\\\/\\\ \/\/
///\//\/\\//\/\//\//\///////\\\//\\\\//\/\/\\//\\/\//////\\\\\\\///\/\\/ \//
\\///\/\\\/\//\///\\\\\\/\\\\/\\/\\//\/\\\/\\\/\/\//\///\\///\/\///\//// \/\
\////\\////\\/\\\/\/\///\///\//\/\/\\/\/\/\\\///\\\\\///\/\\\/\\/\/\\\/ \//\
\\\/\/\\////\\///\//\\\\/\/\\\//\//\////\/\//\/\\\\\/\//\/\//////\\/\\// \\\
\////\\\/////\\\//\\\\//\\\\//\\/\\\\//\/\/\\\\/\///\//\\//\\\\//\/ \//////\
\\\\\//\\\/\\/\////\\//\\//\/\/\/\/////\\/\\//\///\\/\//\\\\\\\///\/\// \/\\
/\/\\//\//\/\\\/////\\\/\\\//\//\////\\///\/\//\\\\\/\/\//////\\/\\/\\/ \///
\/\//\//\//\\///\\\//\\////////\\\\//\//\//\\\/\\///\/\/\/\///\/\////\/\ \\/ //\\\
///\\
\\\\\
/\\//
\\\//

ans:

Maze #:
Cycles; the longest has length . Maze #:
There are no cycles. Maze #:
Cycles; the longest has length . Maze #:
Cycles; the longest has length . Maze #:
Cycles; the longest has length . Maze #:
Cycles; the longest has length . Maze #:
Cycles; the longest has length . Maze #:
There are no cycles. Maze #:
There are no cycles. Maze #:
Cycles; the longest has length . Maze #:
Cycles; the longest has length .

uva 705的更多相关文章

  1. UVA 705 Slash Maze

     Slash Maze  By filling a rectangle with slashes (/) and backslashes ( ), you can generate nice litt ...

  2. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

  3. 1Z0-053 争议题目解析705

    1Z0-053 争议题目解析705 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 705.View Exhibit1 to examine the DATA disk group ...

  4. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  5. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  6. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  7. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  8. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  9. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

随机推荐

  1. Codeforces 479D - Long Jumps

    479D - Long Jumps, 480B - Long Jumps It , or . If we can already measure both x and y, output . Then ...

  2. (Problem 13)Large sum

    Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ...

  3. Python 2.7 学习笔记 基本语法和函数定义

    本文介绍下python的基本语法 一.变量定义 不需要说明类型,也不需要像js等脚本语言使用var等标识符.直接声明即可,如: num=1 说明:上面语句声明了一个变量num,并在声明时初始化值为 1 ...

  4. php启用gzip压缩

    GZIP(GNU-ZIP)是一种压缩技术.经过GZIP压缩后页面大小可以变为原来的30%甚至更小.这样用户浏览的时候就会感觉很爽很愉快! 要实现GZIP压缩页面需要浏览器和服务器共同支持,实际上就是服 ...

  5. Linux下VNC的安装和开机启动

    1.确认VNC是否安装默认情况下,Red Hat Enterprise Linux安装程序会将VNC服务安装在系统上.确认是否已经安装VNC服务及查看安装的VNC版本[root@testdb ~]# ...

  6. 快速解决PDF文档加密不能打印问题_百度经验

    快速解决PDF文档加密不能打印问题_百度经验     快速解决PDF文档加密不能打印问题         |        浏览:182        |        更新:2014-01-06 1 ...

  7. Mac中使用svn进行项目管理

    Mac中使用svn进行项目管理,借鉴了http://blog.csdn.net/q199109106q/article/details/8655204 下面方案多人亲測可用 转载请注明出处:http: ...

  8. Windows API获取系统配置文件的配置参数

    在Windows平台下获取系统配置文件(如:System.ini)的配置参数. 系统配置文件System.ini的内容如下: [SYSTEM] ServiceIP = 10.128.11.99:600 ...

  9. 数据库迁移 - SQLServer->MySQL

    SqlServer转换为Mysql的一款工具推荐(mss2sql)

  10. 闲扯 Javascript 03 时钟和QQ延时框

    时钟 : 所用到得图片  : 开启定时器 setInterval  间隔型 setTimeout  延时型 停止定时器 clearInterval clearTimeout 效果思路 获取系统时间 D ...