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

poj 1164 The Castle

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

poj 1164 The Castle

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<iostream>#define N 60using namespace std;bool map[N][N];int castle[N][N];int room=0;//房间数int step,p,q;//step为搜索时走的步数,即当前房间的面积bool inmap(int x,int y){//judge if the point is in the map    return ( x<=p && y<=q && x>0 && y>0 );}void search(int x,int y){//search from (x,y)    step++;    map[x][y] = true;    int temp = castle[x][y];    if (temp < 8){//do not have the south wall        if( inmap(x+1,y) && !map[x+1][y] ) search(x+1,y);    }    else temp -= 8;    if (temp < 4){//do not have the east wall        if( inmap(x,y+1) && !map[x][y+1] ) search(x,y+1);    }    else temp -= 4;    if (temp < 2){//do not have the north wall        if( inmap(x-1,y) && !map[x-1][y] ) search(x-1,y);    }    else temp -= 2;    if (temp < 1){//do not have the west wall        if( inmap(x,y-1) && !map[x][y-1] ) search(x,y-1);    }}int main(){    cin >> p >> q;    //input    for(int i=1;i<=p;i++)        for(int j=1;j<=q;j++) cin >> castle[i][j];    //init    memset(map,false,sizeof(map));     //search    int lar = 0;    for(int i=1;i<=p;i++)        for(int j=1;j<=q;j++){ if( !map[i][j] ){     step = 0;     search(i,j);     room++;     if(lar < step )//find the largest room         lar = step; }        }    //output    cout << room <<endl;    cout << lar << endl;    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375593.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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