当前位置:网站首页>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);
}
边栏推荐
- 穿越派 你的数据云行
- SystemVerilog学习-06-类的封装
- In win10 and win11, the scroll direction of Elan touch panel is reversed, and "double finger click to open the right-click menu" and "double finger scroll" are started“
- 2022 the 8th China International "Internet +" college student innovation and entrepreneurship competition industry proposition track is open for registration!
- Timer based on LabVIEW
- This is the necessary software for college students 𞓜 knowledge management
- 关于一道01背包问题的·拓展题的思考
- 不是你脑子不好用,而是因为你没有找到对的工具
- Through cooperation with the University of international trade, we can increase efficiency for college students
- Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432
猜你喜欢
Skywalking integrated Nacos dynamic configuration
excel动态图表
uniapp树形层级选择器
Essay learning record essay multi label Global
可动的机械挂钟
Diagramme dynamique Excel
TiDB单机模拟部署生产环境集群(闭坑实践,亲测有效)
Advanced drawing skills of Excel lecture 100 (1) - use Gantt chart to show the progress of the project
Crossing pie · pie pan + Mountain duck = local data management
Send you through the data cloud
随机推荐
LED lighting used in health lighting
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
Code shoe set - mt3149 · and - the data is not very strong. Violent pruning can deceive AC
In win10 and win11, the scroll direction of Elan touch panel is reversed, and "double finger click to open the right-click menu" and "double finger scroll" are started“
DHT11 temperature and humidity sensor
Crossing sect · paipan + Siyuan notes = private notebook
Solve the problem of garbled files uploaded by Kirin v10
论文学习记录随笔 多标签之LIFT
2022 the 8th China International "Internet +" college student innovation and entrepreneurship competition industry proposition track is open for registration!
Highmap gejson data format conversion script
kotlin位运算的坑(bytes[i] and 0xff 报错)
基于LabVIEW的计时器
SystemVerilog学习-07-类的继承和包的使用
π disk, turning your computer into a personal private cloud
Linux closes the redis process SYSTEMd+
Some errors encountered in MySQL data migration
SOE空间分析服务器 MySQL以及PostGres的地理空间库PostGIS防注入攻击
Index method and random forest to realize the information of surface water body in wet season in Shandong Province
Thoughts on a "01 knapsack problem" expansion problem
2022 年面向初学者的 10 大免费 3D 建模软件