当前位置:网站首页>Diffusion (multi-source search)
Diffusion (multi-source search)
2022-07-01 06:07:00 【Great intelligence】
Xiaolan paints on an infinite special canvas .
This canvas can be seen as a grid , Each lattice can be represented by a two-dimensional integer coordinate .
Xiao Lan first made a few dots on the canvas :(0, 0), (2020, 11), (11, 14), (2000, 2000)
Only these squares have black , The rest of the place is white .
Every minute , The black will spread a little bit . Concrete , If the inside of a grid is black , It's going to spread to 、 Next 、 Left 、 In the right four adjacent squares , Make these four squares black ( If it turns out to be black , It's still black ).
Excuse me, , after 2020 Minutes later , How many squares on the canvas are black .
analysis : Four points spread at the same time , Consider the problem of overlap , And the more points spread in the next second , The first thing I wrote was to search every point separately , If the first point spreads to the second point and has been marked , At the second point, you won't search , The result is wrong ;
So search from multiple sources at the same time , When there is a little overlap , The first source point shows that there is more time left , The range of subsequent diffusion is also the largest , Later, there was less time at the source , The diffusion range is certainly not as large as that of the first ;
Again, why not search widely ,2020 Nodes have high complexity , Long time , Guangsearch can save time through space
#include<bits/stdc++.h>
using namespace std;
int ans=4;
int book[9999][9999];
int nex[4][2]={
0,1,0,-1,1,0,-1,0};
struct node
{
int x,y,z;
}l,head;
queue <node> q;
void bfs()
{
while( !q.empty() )
{
head=q.front();
q.pop();
if(head.z>=2020)
continue;
for(int i=0;i<4;i++)
{
int tx=head.x+nex[i][0];
int ty=head.y+nex[i][1];
if(book[tx][ty]==0)
{
book[tx][ty]=1;
ans++;
l.x=tx;
l.y=ty;
l.z=head.z+1;
q.push(l);
}
}
}
}
int main()
{
book[3000][3000]=1;
book[5020][3011]=1;
book[3011][3014]=1;
book[5000][5000]=1;
l.x=3000;
l.y=3000;
l.z=0;
// q.push(l);
q.push({
3000,3000,0});
// It's OK to write like this , The queue has been specified as structure type in the front
// bfs();
l.x=5020;
l.y=3011;
l.z=0;
q.push(l);
// bfs();
l.x=3011;
l.y=3014;
l.z=0;
q.push(l);
// bfs();
l.x=5000;
l.y=5000;
l.z=0;
q.push(l);
bfs();
printf("%d\n",ans);
}
边栏推荐
- OpenGL es: (2) relationship between OpenGL es, EGL and glsl
- [note] e-commerce order data analysis practice
- Know the future of "edge computing" from the Nobel prize!
- π盘,让您电脑变成个人的私有云
- 让厦门灌口镇田头村变“甜头”村的特色农产品之一是
- 论文学习记录随笔 多标签之LSML
- Call us special providers of personal cloud services for College Students
- 基于LabVIEW的计时器
- golang panic recover自定义异常处理
- Oracle create user + Role
猜你喜欢

2022 年面向初学者的 10 大免费 3D 建模软件

千万不要把笔记视频乱放!

基于LabVIEW的计时器

Transformer le village de tiantou en un village de betteraves sucrières

El tooltip in the table realizes line breaking display

OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)

el-table 动态表头渲染 固定第一列 高度问题

Know the future of "edge computing" from the Nobel prize!

穿越派·派盘 + 思源笔记 = 私人笔记本

TiDB单机模拟部署生产环境集群(闭坑实践,亲测有效)
随机推荐
SystemVerilog学习-08-随机约束和线程控制
Seven major technical updates that developers should pay most attention to on build 2022
jdbc 数据库操作
linux 关闭redis 进程 systemd+
Crossing pie · pie pan + Mountain duck = local data management
利用百度地图查询全国地铁线路
π盘,让您电脑变成个人的私有云
Solve the problem of garbled files uploaded by Kirin v10
Orcle创建用户+角色
Oracle sequence + trigger
2022 the 8th China International "Internet +" college student innovation and entrepreneurship competition industry proposition track is open for registration!
How to add a gourd pie plate
Infinite horizontal marble game
健康照明中应用的LED照明灯
OpenGL es: (2) relationship between OpenGL es, EGL and glsl
千万不要把笔记视频乱放!
make: g++:命令未找到
浏览器端保存数据到本地文件
restframework-simpleJWT重写认证机制
芯片,建立在沙粒上的帝国!