栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2980 Key Task

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2980 Key Task

#include <cmath>#include <cstdio>#include <cstdlib>#include <map>#include <set>#include <list>#include <deque>#include <queue>#include <stack>#include <bitset>#include <vector>#include <string>#include <limits>#include <algorithm>#include <cstring> #include <functional>using namespace std;const int dir[4][2] = {    {1, 0},    {0, -1},    {-1, 0},    {0, 1}};struct Status{    char x, y, z;};inline int c2i(char c){    switch(c)    {    case 'b': return 1;    case 'y': return 2;    case 'r': return 4;    case 'g': return 8;    }    return 0;}inline int C2i(char C){    switch(C)    {    case 'B': return 1;    case 'Y': return 2;    case 'R': return 4;    case 'G': return 8;    }    return 0;}char mp[102][102];int mind[102][102][16];Status q[100 * 100 * 16];int p, t;int main(void){    static int r, c, ans;    static int x, y, z, xx, yy, zz;    memset(mp[0], '#', sizeof(mp[0]));    while(scanf("%d%d", &r, &c) != EOF && r + c > 0) {        p = t = 0;        for (int i = 1; i <= r; i++) { mp[i][0] = '#'; scanf("%s", mp[i] + 1); for (int j = 1; j <= c; j++) {     for (int k = 0; k < 16; k++)         mind[i][j][k] = -1;     if(mp[i][j] == '*') {         q[t].x = i;         q[t].y = j;         q[t].z = 0;         mind[i][j][0] = 0;         ++t;         mp[i][j] = '.';     } } mp[i][c + 1] = '#';        }        memset(mp[r + 1], '#', (c + 1) * sizeof(char));        ans = -1;        while(p < t) { x = q[p].x; y = q[p].y; z = q[p].z; for (int d = 0; d < 4; d++) {     xx = x + dir[d][0];     yy = y + dir[d][1];     if(mp[xx][yy] == '#')         continue;     else if(mp[xx][yy] == 'X') {         ans = mind[x][y][z] + 1;         p = t;         break;     }     else if(mp[xx][yy] == '.') {         zz = z;         if(mind[xx][yy][zz] != -1)  continue;     }     else if(islower(mp[xx][yy])) {         zz = (z | c2i(mp[xx][yy]));         if(mind[xx][yy][zz] != -1)  continue;     }     else if(isupper(mp[xx][yy])) {         zz = z;         if((zz & C2i(mp[xx][yy])) == 0 || mind[xx][yy][zz] != -1)  continue;     }     else         continue;     q[t].x = xx;     q[t].y = yy;     q[t].z = zz;     mind[xx][yy][zz] = mind[x][y][z] + 1;     ++t; } ++p;        }        if(ans == -1) puts("The poor student is trapped!");        else printf("Escape possible in %d steps.n", ans);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372182.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号