当前位置:网站首页>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);
}
边栏推荐
猜你喜欢

Don't put your notes and videos everywhere!

This is the necessary software for college students 𞓜 knowledge management

TiDB单机模拟部署生产环境集群(闭坑实践,亲测有效)

数据库问题,如何优化Oracle SQL查询语句更快,效率更高

Why use huluer pie disk instead of U disk?

OpenGL es: (5) basic concepts of OpenGL, the process of OpenGL es generating pictures on the screen, and OpenGL pipeline

What if the data in the cloud disk is harmonious?

论文学习记录随笔 多标签之LIFT

linux 关闭redis 进程 systemd+

68 Cesium代码datasource加载czml
随机推荐
OpenGL es: (3) EGL, basic steps of EGL drawing, eglsurface, anativewindow
Oracle sequence + trigger
不是你脑子不好用,而是因为你没有找到对的工具
SystemVerilog学习-07-类的继承和包的使用
OpenGL ES: (3) EGL、EGL绘图的基本步骤、EGLSurface、ANativeWindow
Codeforces Round #803 (Div. 2)vp
Call us special providers of personal cloud services for College Students
Diagramme dynamique Excel
Crossing sect · paipan + Siyuan notes = private notebook
He struggled day and night to protect his data
C language beginner level - realize the minesweeping game
穿越派·派盘 + 思源笔记 = 私人笔记本
OpenGL ES: (4) EGL API详解 (转)
Huluer app help
C XML help class
Transformer le village de tiantou en un village de betteraves sucrières
PLA not pasted on the bed: 6 simple solutions
excel動態圖錶
无限水平大理石游戏
68 Cesium代码datasource加载czml