poj 3083 -- Children of the Candy Corn

本文介绍了一个迷宫路径寻找算法,通过深度优先搜索(DFS)找到靠左和靠右的路径长度,并利用广度优先搜索(BFS)确定最短路径长度。此算法适用于帮助设计者评估迷宫布局对游客挑战性的大小。
Children of the Candy Corn
 
 
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9544 Accepted: 4136

Description

The cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, and other terrors on their quest to find the exit.

One popular maze-walking strategy guarantees that the visitor will eventually find the exit. Simply choose either the right or left wall, and follow it. Of course, there's no guarantee which strategy (left or right) will be better, and the path taken is seldom the most efficient. (It also doesn't work on mazes with exits that are not on the edge; those types of mazes are not represented in this problem.)

As the proprieter of a cornfield that is about to be converted into a maze, you'd like to have a computer program that can determine the left and right-hand paths along with the shortest path so that you can figure out which layout has the best chance of confounding visitors.

Input

Input to this problem will begin with a line containing a single integer n indicating the number of mazes. Each maze will consist of one line with a width, w, and height, h (3 <= w, h <= 40), followed by h lines of w characters each that represent the maze layout. Walls are represented by hash marks ('#'), empty space by periods ('.'), the start by an 'S' and the exit by an 'E'.

Exactly one 'S' and one 'E' will be present in the maze, and they will always be located along one of the maze edges and never in a corner. The maze will be fully enclosed by walls ('#'), with the only openings being the 'S' and 'E'. The 'S' and 'E' will also be separated by at least one wall ('#').

You may assume that the maze exit is always reachable from the start point.

Output

For each maze in the input, output on a single line the number of (not necessarily unique) squares that a person would visit (including the 'S' and 'E') for (in order) the left, right, and shortest paths, separated by a single space each. Movement from one square to another is only allowed in the horizontal or vertical direction; movement along the diagonals is not allowed.

Sample Input

2
8 8
########
#......#
#.####.#
#.####.#
#.####.#
#.####.#
#...#..#
#S#E####
9 5
#########
#.#.#.#.#
S.......E
#.#.#.#.#
#########

Sample Output

37 5 5
17 17 9

思路:依次DFS出右转左转的步数,BFS出最小步数。。

  1 /*======================================================================
  2  *           Author :   kevin
  3  *         Filename :   ChildrwenOftheCandyCorn.cpp
  4  *       Creat time :   2014-06-08 15:37
  5  *      Description :
  6 ========================================================================*/
  7 #include <iostream>
  8 #include <algorithm>
  9 #include <cstdio>
 10 #include <cstring>
 11 #include <queue>
 12 #include <cmath>
 13 #define clr(a,b) memset(a,b,sizeof(a))
 14 #define M 50
 15 using namespace std;
 16 char grap[M][M];
 17 int w,h,sx,sy,ex,ey;
 18 int vis[M][M],cntl,cntr;
 19 int minsteps[M][M];
 20 int dir0[4][2]={{0,-1},{-1,0},{0,1},{1,0}};//dfs needed
 21 int dir[4][4][2] = {//bfs needed
 22                 {{0,-1},{-1,0},{0,1},{1,0}},
 23                 {{-1,0},{0,1},{1,0},{0,-1}},
 24                 {{0,1},{1,0},{0,-1},{-1,0}},
 25                 {{1,0},{0,-1},{-1,0},{0,1}}
 26 };
 27 struct Node
 28 {
 29     int x,y;
 30 };
 31 void BFS()
 32 {
 33     queue<Node>que;
 34     Node node;
 35     node.x = sx; node.y = sy;
 36     que.push(node);
 37     vis[sx][sy] = 1;
 38     minsteps[sx][sy] = 1;
 39     int flag = 0;
 40     while(que.empty() != true){
 41         Node T = que.front();
 42         que.pop();
 43         if(T.x == ex && T.y == ey) return ;
 44         for(int i = 0; i < 4; i++){
 45             int x = T.x + dir[1][i][0];
 46             int y = T.y + dir[1][i][1];
 47             if(grap[x][y] == '.' && !vis[x][y]){
 48                 node.x = x; node.y = y;
 49                 vis[x][y] = 1;
 50                 que.push(node);
 51                 minsteps[x][y] = minsteps[T.x][T.y]+1;
 52             }
 53             else if(grap[x][y] == 'E'){
 54                 minsteps[x][y] = minsteps[T.x][T.y]+1;
 55                 flag = 1; break;
 56             }
 57         }
 58         if(flag) break;
 59     }
 60 }
 61 int lDFS(int i,int j,int s,int now)
 62 {
 63     if(grap[i][j]=='E')return s;
 64     for(int d=now;d<now+4;++d)
 65     {
 66         int di=i+dir0[d%4][0];
 67         int dj=j+dir0[d%4][1];
 68         if(d<=0)d+=4;
 69         if(grap[di][dj]!='#')return lDFS(di,dj,s+1,(d-1)%4);
 70         d%=4;
 71     }
 72     return -1;
 73 }
 74 int rDFS(int i,int j,int s,int now)
 75 {
 76     if(grap[i][j]=='E')return s;
 77     for(int d=now+4;d>now;--d)
 78     {
 79         int di=i+dir0[d%4][0];
 80         int dj=j+dir0[d%4][1];
 81         if(grap[di][dj]!='#')return rDFS(di,dj,s+1,(d+1)%4);
 82     }
 83     return -1;
 84 }
 85 int main(int argc,char *argv[])
 86 {
 87     int cas;
 88     scanf("%d",&cas);
 89     while(cas--){
 90         scanf("%d%d",&w,&h);
 91         clr(vis,0);
 92         memset(grap,'#',sizeof(grap));
 93         clr(minsteps,0);
 94         for(int i = 1; i <= h; i++){
 95             getchar();
 96             for(int j = 1; j <= w; j++){
 97                 scanf("%c",&grap[i][j]);
 98                 if(grap[i][j] == 'S'){
 99                     sx = i; sy = j;
100                 }
101                 if(grap[i][j] == 'E'){
102                     ex = i; ey = j;
103                 }
104             }
105         }
106         printf("%d %d ",lDFS(sx,sy,1,0),rDFS(sx,sy,1,0));
107         BFS();
108         printf("%d\n",minsteps[ex][ey]);
109     }
110     return 0;
111 }
View Code

 

转载于:https://www.cnblogs.com/ubuntu-kevin/p/3885258.html

一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值