调了好久。。。

#include <cstdio>
#include <queue>
using namespace std; char a[110*110];
/**************************************
000000000000
000000000000
00----####00
00###----#00 //like dis
00##--##--00
000000000000
000000000000
**************************************/
int visited[110*110];
int cnt;
int of1x[] = {-1, 0, 1, 0};
int of1y[] = {0, -1, 0, 1};
int of2x[] = {0, 1, 2, 1, 0, -1, -2, -1};
int of2y[] = {2, 1, 0, -1, -2, -1, 0, 1}; int main(){
int m, n;
scanf("%d%d", &m, &n);
getchar(); for(int i = 2; i < m+2; ++i){
for(int j = 2; j < n+2; ++j){
a[i*(n+4)+j] = getchar();
}
getchar();
} n = n+4;
queue<int> Q;
for(int i = 0; i < (m+4)*n-1; ++i){
if(!visited[i] && a[i] == '#'){
int now = i;
visited[now] = 2;
cnt++;
Q.push(now); do{
//搜索附近
now = Q.front();
Q.pop(); int x = now%n;
int y = now/n; if(visited[now] == 2){ //now是第二圈
for(int ii = 0; ii < 4; ++ii){
int pos = (y+of1y[ii])*n + (x+of1x[ii]);
if(!visited[pos] && a[pos] == '#'){
visited[pos] = 1;
Q.push(pos);
}
}
} for(int ii = 0; ii < 8; ++ii){
int pos = (y+of2y[ii])*n + (x+of2x[ii]);
if(!visited[pos] && a[pos] == '#'){
visited[pos] = 2;
Q.push(pos);
}
}
}while(!Q.empty());
}
} printf("%d", cnt);
return 0;
}

vijos P1051 送给圣诞夜的极光的更多相关文章

  1. 【宽搜】Vijos P1051 送给圣诞夜的极光

    题目链接: https://vijos.org/p/1051 题目大意: 给一张‘-’和‘#’的图,规定曼哈顿距离小于等于2的‘#’属于同一图案,求图案数.[曼哈顿距离:对于A(x1,y1)和B(x2 ...

  2. [vijos]1051送给圣诞夜的极光<BFS>

    送给圣诞夜的极光 题目链接:https://www.vijos.org/p/1051 这是一道很水很水的宽搜水题,我主要是觉得自己在搜素这一块有点生疏于是随便找了一题练手,找到这么一道水题,原本以为可 ...

  3. Codevs 1293 送给圣诞夜的极光

    1293 送给圣诞夜的极光  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 圣诞老人回到了北极圣 ...

  4. codevs1293送给圣诞夜的极光(bfs)

    1293 送给圣诞夜的极光  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold     题目描述 Description 圣诞老人回到了北极圣诞区,已经快到12点了 ...

  5. Vijos1051. 送给圣诞夜的极光

    试题请參见: https://vijos.org/p/1051 题目概述 圣诞老人回到了北极圣诞区, 已经快到12点了. 也就是说极光表演要開始了. 这里的极光不是极地特有的自然极光景象. 而是圣诞老 ...

  6. 洛谷 P1454 圣诞夜的极光 == codevs 1293 送给圣诞夜的极光

    题目背景 圣诞夜系列~~ 题目描述 圣诞老人回到了北极圣诞区,已经快到12点了.也就是说极光表演要开始了.这里的极光不是极地特有的自然极光景象.而是圣诞老人主持的人造极光. 轰隆隆……烟花响起(来自中 ...

  7. vijos 1047 送给圣诞夜的礼品 矩阵

    题目链接 描述 当小精灵们把贺卡都书写好了之后.礼品准备部的小精灵们已经把所有的礼品都制作好了.可是由于精神消耗的缘故,他们所做的礼品的质量越来越小,也就是说越来越不让圣诞老人很满意.可是这又是没有办 ...

  8. P1049送给圣诞夜的礼品(矩阵十大问题之四)

    https://vijos.org/p/1049 P1049送给圣诞夜的礼品 Accepted 标签:组合数学送给圣诞夜的礼物[显示标签]     返回代码界面 | 关闭   Pascal Pasca ...

  9. vijosP1049 送给圣诞夜的礼品

    vijosP1049 送给圣诞夜的礼品 链接:https://vijos.org/p/1049 [思路] 快速幂+矩阵转换. 将m次矩阵的转换看作是一次快速幂中的乘法操作,这样可以用O(log(k/m ...

随机推荐

  1. Visual Studio Code 配置Go 开发环境最简单的方法!!!

    由于大家都知道的原因,在国内如果想访问go等各种资源,都会遇到某种不可预知的神奇问题.导致在VS Code中安装 go 各种插件都会失败. 于是乎,网上就出现了各种各样的解决方案:什么手动git cl ...

  2. 论文翻译--StarCraft Micromanagement with Reinforcement Learning and Curriculum Transfer Learning

    (缺少一些公式的图或者效果图,评论区有惊喜) (个人学习这篇论文时进行的翻译[谷歌翻译,你懂的],如有侵权等,请告知) StarCraft Micromanagement with Reinforce ...

  3. Linux arm64内核启动

    原创翻译,转载请注明出处. arm64的异常模型由一组异常级别(EL0-EL3)组成.EL0,EL1有安全模式和非安全模式的区别.EL2是虚拟机管理级别并且只有非安全模式.EL3是最高优先级并且只存在 ...

  4. C# Lambda表达式使用累加器例子

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Lamb ...

  5. clientHeight & clientWidth & offsetHeight & offsetWidth & outerWidth & innerWidth & outerWidth & outerHeight

    clientHeight & clientWidth & offsetHeight & offsetWidth MDN https://developer.mozilla.or ...

  6. [剑指Offer] 36.两个链表的第一个公共结点

    题目描述 输入两个链表,找出它们的第一个公共结点. [思路]找出两个链表的长度,然后让长的走两个链表的长度差,然后再一起走(因为两个链表用公共的尾部). /* struct ListNode { in ...

  7. maven release版本重复上传error

    A couple things I can think of: user credentials are wrong url to server is wrong user does not have ...

  8. NS10.1 产品技术规范

    NS10.1 产品技术规范 产品技术规范==================4层-7层流量管理 4层负载均衡(LB)        支持的协议TCP,UDP,FTP,HTTP,HTTPS,DNS(TC ...

  9. HDU 6194 string string string(后缀数组+RMQ)

    string string string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  10. [Leetcode] word break ii拆分词语

    Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each ...