北大 ACM 1111题
来源:互联网 发布:法线贴图制作软件 编辑:程序博客网 时间:2024/05/16 04:54
北大ACM 网站题 1111,
http://poj.org/problem?id=1111
题目:
求图像的周长。
利用广度优先解决的代码:
#include <stdio.h>
#include <stack>
using namespace std;
char Picture[20][20];
int perimeter=0;
int MaxRow,MaxCol;
stack<int> OpenStack;
void readData(int row , int col)
{
int i,j;
fflush(stdin);
for(i=0; i<row ;i++)
{
for(j=0 ; j<col ;j++)
Picture[i][j]=getchar();
fflush(stdin);
}
}
void place(int x ,int y)
{
Picture[x][y]='A';
}
int isBound(int x,int y)
{
if(x==-1 || x==MaxRow || y==-1 || y==MaxCol )
return 1;
else if(Picture[x][y]=='.')
return 1;
return 0;
}
int canPlace(int x ,int y)
{
if(x>=0 && x<MaxRow && y>=0 && y<MaxCol)
if(Picture[x][y]=='X')
return 1;
return 0;
}
void search(int row , int col)
{
int tempRow,tempCol,tempInt;
int i,j;
place(row,col);
OpenStack.push(row*MaxCol +col);
while(!OpenStack.empty())
{
tempInt =OpenStack.top();
OpenStack.pop();
row=tempInt/MaxCol;
col=tempInt%MaxCol;
for(i=-1 ; i<=1 ;i++)
for(j=-1 ;j<=1 ;j++)
if(!(i==0&&j==0))
{
tempRow=row+i;
tempCol=col+j;
if((i==0 || j==0)&&isBound(tempRow,tempCol))
perimeter++;
else
if(canPlace(tempRow,tempCol))
{
place(tempRow,tempCol);
OpenStack.push(tempRow*MaxCol+tempCol);
}
}
}
}
int main()
{
int x,y;
scanf("%d %d %d %d",&MaxRow,&MaxCol,&x,&y);
readData(MaxRow,MaxCol);
while(MaxRow!=0)
{
search(x-1,y-1);
printf("%d/n",perimeter);
perimeter=0;
scanf("%d %d %d %d",&MaxRow,&MaxCol,&x,&y);
readData(MaxRow,MaxCol);
}
return 0;
}
- 北大 ACM 1111题
- 北大ACM题分类
- 北大ACM题分类
- 北大ACM题分类
- 北大ACM题分类
- 北大ACM题分类
- POJ --北大ACM题分类
- 北大ACM 做题顺序
- 北大ACM
- 北大 poj acm题目推荐50题
- 值得做的北大ACM题
- 北大 poj acm题目推荐50题
- ACM北大的第1001题
- 北大ACM-题型分类
- 北大ACM题型分类
- 北大ACM做题小软件
- 北大acm 题型分类
- 北大ACM分类初期
- Linux console
- Cassandra 概况
- web.config中的HttpHandler
- vma->vm_pgoff
- Mentor with the correct "Renaissance" started out inside 1997
- 北大 ACM 1111题
- 如何通过网络调用WebService远程控制电灯泡开关灯
- Java保留小数问题
- linux下远程连接oracle数据库
- java notify() 与 notifyAll() 区别
- suse 11.4 安装fcitx 4 并解决firefox不能调出中文问题
- 内核虚拟地址与物理地址的关系
- 条款6:析构函数里对指针成员调用delete
- UBUNTU中如何修改root密码