题意,给你迷宫算出其中个封闭空间的个数,以及求出所有封闭的空间的最大步长,但是给你的迷宫式“/”,“\”来标记的所以需要将每个格子分开来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. JVM -- 类加载

    学习自周志明老师的<深入理解Java虚拟机>第二版 类的加载时机 如上图所示: 类从被加载到虚拟机内存中开始,直到卸载出内存为止,它的整个生命周期包括了: 加载.验证.准备.解析.初始化. ...

  2. CodeForces 543A - Writing Code DP 完全背包

    有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b, 给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下, 我们有几种选择方法思路:看懂了题意之后 ...

  3. GDG shanghai programming one hour by JavaScript

    刚在昨天参加了一场JS入门编程的活动,目的就是提升对JS的兴趣. 因为是针对零基础开发者的,一上来就是“Hello World!”了 当然,想用JS输出"Hello World!" ...

  4. jquery删除动态增加的li

    <script type="text/jscript"> //楼主帮你修改调整了下 $(document).ready(function () { $('.zuo li ...

  5. td

    http://jameswxx.iteye.com/blog/1041173 http://crane-ding.iteye.com/blog/968862 http://www.ibm.com/de ...

  6. 转:Javascript的10个设计缺陷

    作者: 阮一峰 日期: 2011年6月30日 前几篇文章,我经常说Javascript的设计不够严谨,有很多失误. 今天的这一篇,前半部分就谈为什么会这样,后半部分将列举Javascript的10个设 ...

  7. H面试程序(28):字符串处理转换

    //2 字符串处理转换 //问题描述: //在给定字符串中找出单词( “单词”由大写字母和小写字母字符构成, //其他非字母字符视为单词的间隔,如空格.问号.数字等等:另外单个字母不算单词): //找 ...

  8. 46黑名单显示的bug---(优化ListView)convertView复用带来的问题

    是这种需求: 在黑名单的列表中前三个显示特殊的颜色,后面的列表显示其它的颜色,如图: 可是当翻到第二屏的时候.我们发现了: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...

  9. Python获取当地的天气和随意城市的天气

    先从中国天气网得到数据('http://www.weather.com.cn/data/cityinfo/'+城市编码),每一个城市都有各自的编码,怎样得到用户所在地的城市编码呢?用一个网页就是专门干 ...

  10. 再写KMP算法

    #include<iostream> #include<string> using namespace std; void getNext(char const*T,int l ...