zoukankan      html  css  js  c++  java
  • uva-705-深搜

    题意,就是根据斜线组成的迷宫,判断能够组成多少个闭环.

    解法:

    放大俩倍或者三倍

    俩倍

        ------->10

          01

    三倍

      ------->100

           010

           001

    然后深搜,有个问题,没有判断是否成环,它竟然过了,待证明----它到底对不对

    #include<stdio.h>
    #include<iostream>
    #include<queue>
    #include<memory.h>
    using namespace std;
    const int MAX = 80 * 3;
    int maps[MAX][MAX];
    int r, c;
    void dfs(int x, int y, int tr, int tc, int* total, int* ok)
    {
    	*total = *total + 1;
    	maps[x][y] = 1;
    	if(x == 0 || x == (tr - 1) || y == 0 || y == (tc - 1))
    		*ok = 0;
    	if(x > 0 && maps[x - 1][y] == 0)
    		dfs(x - 1, y, tr, tc, total, ok);
    	if(y > 0 && maps[x][y - 1] == 0)
    		dfs(x, y - 1, tr, tc, total, ok);
    	if(x < (tr - 1) && maps[x + 1][y] == 0)
    		dfs(x + 1, y, tr, tc, total, ok);
    	if(y < (tc - 1) && maps[x][y + 1] == 0)
    		dfs(x, y + 1, tr, tc, total, ok);
    
    }
    
    int main()
    {
    	freopen("d:\1.txt", "r", stdin);
    	int T = 1;
    	while (cin >> c >> r)
    	{
    		if(r == 0 && c == 0)
    			return 0;
    		memset(maps, 0, sizeof(maps));
    		char cc;
    		for(int i = 0; i < r; i++)
    		{
    			for(int j = 0; j < c; j++)
    			{
    				cin >> cc;
    				if(cc == '/')
    				{
    					maps[3 * i][3 * j + 2] = 1;
    					maps[3 * i + 1][3 * j + 1] = 1;
    					maps[3 * i + 2][3 * j] = 1;
    				}
    				else if(cc == '\')
    				{
    					maps[3 * i][3 * j] = 1;
    					maps[3 * i + 1][3 * j + 1] = 1;
    					maps[3 * i + 2][3 * j + 2] = 1;
    				}
    			}
    		}
    		int mr = 3 * r;
    		int mc = 3 * c;
    		int t = 0;
    		int max = 0;
    		for(int i = 0; i < mr; i++)
    			for(int j = 0; j < mc; j++)
    			{
    				if(maps[i][j] == 0)
    				{
    					int ok = 1;
    					int total = 0;
    					dfs(i, j, mr, mc, &total, &ok);
    					if(ok)
    					{
    						max = max > total ? max : total;
    						t++;
    					}
    				}
    			}
    
    		cout << "Maze #" << T << ":" << endl;
    		if(t == 0)
    			cout << "There are no cycles." << endl;
    		else
    			cout << t << " Cycles; the longest has length " << max / 3 << "."
    					<< endl;
    		cout << endl;
    		T++;
    
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    FineBI客户画像分析与客户价值模型快速入门
    大数据分析免费学习教程
    Xshell连接不上Ubuntu解决方式
    Jenkins时区设置为北京时间
    ASP.NET Core 与支付宝开发文档
    .NET Core 从 Github到 Nuget 持续集成、部署
    使用 dotnet cli 命令上传 nuget 程序包
    发布你的程序包到Nuget
    ASP.NET Core 判断请求是否为Ajax请求
    ASP.NET Core 如何在运行Docker容器时指定容器外部端口(docker compose)
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/6883473.html
Copyright © 2011-2022 走看看