山东省第7届ACM省赛 E题
来源:互联网 发布:知乎年度精选 编辑:程序博客网 时间:2024/06/04 23:25
D - The Binding of Isaac
Time Limit: 2000 ms / Memory Limit: 65536 kb
Description
Ok, now I will introduce this game to you...
Isaac is trapped in a maze which has many common rooms…
Like this…There are 9 common rooms on the map.
And there is only one super-secret room. We can’t see it on the map. The super-secret room always has many special items in it. Isaac wants to find it but he doesn’t know where it is.Bob
tells him that the super-secret room is located in an empty place which is adjacent to only one common rooms.
Two rooms are called adjacent only if they share an edge. But there will be many possible places.
Now Isaac wants you to help him to find how many places may be the super-secret room.
Input
Multiple test cases. The first line contains an integer T (T<=3000), indicating the number of test case.
Each test case begins with a line containing two integers N and M (N<=100, M<=100) indicating the number
of rows and columns. N lines follow, “#” represent a common room. “.” represent an empty place.Common rooms
maybe not connect. Don’t worry, Isaac can teleport.
Output
One line per case. The number of places which may be the super-secret room.
Sample Input
2
5 3
..#
.##
##.
.##
##.
1 1
#
Sample Output
8
4
题意大概是若每个点旁边只要有一个#,就算符合题意的点,求点的个数。注意所有的输入示例的外层可能都存在着点。所以输入的时候提前将周边的点输入。
然后利用函数查找,遍历四个方向,若只找到一个#,返回1,其他的返回0.暴力即可解决。
#include<stdio.h>
#include<string.h>
int next[4][2]={0,1,1,0,0,-1,-1,0}; //方向数组
int m,n;
char map[105][105]; //储存地图
int find(int x,int y) //查找函数
{
int tx,ty,k,count; //count用来记录,tx,ty接收下一个 方向
count=0;
for(k=0;k<4;k++)
{
tx=next[k][0]+x;
ty=next[k][1]+y;
if(tx<0||tx>n+1||ty<0||ty>m+1) //越界判断
continue;
if(map[tx][ty]=='#') //找到#
{
count++;
}
if(count>=2) //大于2 直接返回
return 0;
}
if(count==1)
return 1;
return 0;
}
int main()
{
int t,i,j,sum;
scanf("%d",&t);
while(t--)
{
memset(map,0,sizeof(map)); //清空map,貌似没用
scanf("%d%d",&n,&m);
getchar(); //吸收回车
sum=0;
for(j=1;j<=m;j++) //外围加上点
{
map[0][j]='.';
map[n+1][j]='.';
}
for(i=1;i<=n;i++) //外围加点,但四个角不要
{
map[i][0]='.';
map[i][m+1]='.';
}
for(i=1;i<=n;i++) //输入
{
for(j=1;j<=m;j++)
scanf("%c",&map[i][j]);
getchar();
}
for(i=0;i<=n+1;i++) //遍历
for(j=0;j<=m+1;j++)
{
if(map[i][j]=='.')
sum+=find(i,j);
}
printf("%d\n",sum);
}
return 0;
}
- 山东省第7届ACM省赛 E题
- 山东省第八届acm省赛E题 三分+二分
- 第七届山东省ACM省赛 E The Binding of Isaac
- 山东省第七届ACM大赛E题题解
- 山东省第7届ACM省赛 F题 Feed the monkey dp
- 山东省第7届省赛 E题 The Binding of Isaac
- 山东省第八届ACM省赛C题
- 山东省第八届ACM省赛A题
- 山东省第四届acm省赛
- 山东省第三届ACM省赛
- 山东省第一届ACM省赛 E SDUT 2155 Emergency(最短路)
- 山东省第五届ACM大赛--Problem E: Full Binary Tree
- 第七届ACM山东省赛-E The Binding of Isaac
- 山东省第二届ACM省赛 F题 Manhattan 解题报告
- Binomial Coeffcients 山东省第二届ACM省赛 G题
- 2016山东省第七届acm省赛 G题Triple Nim
- sdut 3258 (第六届山东省ACM省赛H题)
- 2015山东省第六届acm省赛 C题Game!
- Golang Socket Tcp 连接优雅关闭
- Netbeans修改字体、大小、和编辑器背景色
- 使用BigDecimal进行精确运算
- eigen 在vs下的使用(1)
- Dom 中对外联(link标签)css样式的添加和删除
- 山东省第7届ACM省赛 E题
- Condition-线程通信更高效的方式
- Android-源码剖析CountDownTimer(倒计时类)
- Mybatis物理分页插件PageHelper 5.0
- Java抽象类和抽象方法、接口
- Sql 内连接和外连接
- cocos2dx在win10系统上的VS2017运行时报错:丢失MSVCR110.dll
- EventBus全面讲解和案例
- centos7 防火墙问题