当前位置:网站首页>Save Private Ryan - map building + voltage dp+deque+ shortest circuit
Save Private Ryan - map building + voltage dp+deque+ shortest circuit
2022-07-04 01:58:00 【Wawa source】


Topic link
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <deque>
#include <vector>
using namespace std;
#define x first
#define y second
typedef pair<int,int>PII;
const int N = 110,M = 1<<10;
vector<PII>g[N];
set<PII>edges; // Judge whether the edge has been built in the figure
int n,m,p,k;
int dist[N][M]; // The first dimension is coordinates , The second dimension is the key state
bool st[N][M]; // Judge whether it has been updated , If it is updated, it will be the minimum , There is no need to change
int id[12][12]; // Map two dimensions to one dimension , Easy to write
int key[N]; // Record the key of each position , In binary
void build()
{
int dx[4]={
1,0,-1,0},dy[4]={
0,1,0,-1};
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
for(int u=0;u<4;u++)
{
int x=i+dx[u],y=j+dy[u];
if(x<1||x>n||y<1||y>m)continue;
int a=id[i][j],b=id[x][y];
// Build a map while walking that is not built in the map
if(!edges.count({
a,b}))
g[a].push_back({
b,0});
}
}
}
}
int bfs()
{
// deque ,
memset(dist,0x3f,sizeof dist);
deque<PII>q;
q.push_back({
1,0});
dist[1][0]=0;
while(q.size())
{
auto t=q.front();
q.pop_front();
if(st[t.x][t.y])continue;
st[t.x][t.y]=true;
if(t.x==n*m)return dist[t.x][t.y];
// Pick up the key in this position
if(key[t.x])
{
int state=t.y|key[t.x];
if(dist[t.x][state]>dist[t.x][t.y])
{
dist[t.x][state]=dist[t.x][t.y];
q.push_front({
t.x,state});
}
}
for(auto [v,w] : g[t.x])
{
// If you need a key for the next position , But the last point is updated, and you can skip directly without this key
if(w&&!(t.y>>w-1&1))continue;
if(dist[v][t.y]>dist[t.x][t.y]+1)
{
dist[v][t.y]=dist[t.x][t.y]+1;
q.push_back({
v,t.y});
}
}
}
return -1;
}
signed main()
{
cin>>n>>m>>p>>k;
for(int i=1,t=1;i<=n;i++)
for(int j=1;j<=m;j++)
id[i][j]=t++;
for(int i=1;i<=k;i++)
{
int x1,y1,x2,y2,c;
cin>>x1>>y1>>x2>>y2>>c;
int a=id[x1][y1],b=id[x2][y2];
edges.insert({
a,b});
edges.insert({
b,a});
if(c)g[a].push_back({
b,c}),g[b].push_back({
a,c});
}
build();
int s;
cin>>s;
while(s--)
{
int x1,y1,c;
cin>>x1>>y1>>c;
key[id[x1][y1]]|=1<<c-1;
}
cout<<bfs()<<endl;
}
边栏推荐
- From the 18th line to the first line, the new story of the network security industry
- Chain ide -- the infrastructure of the metauniverse
- It's corrected. There's one missing < /script >, why doesn't the following template come out?
- Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
- C import Xls data method summary II (save the uploaded file to the DataTable instance object)
- When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
- Bacteriostatic circle scanning correction template
- 2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
- 2022 new examination questions for safety management personnel of hazardous chemical business units and certificate examination for safety management personnel of hazardous chemical business units
- Huawei cloud micro certification Huawei cloud computing service practice has been stable
猜你喜欢

MySQL deadly serial question 2 -- are you familiar with MySQL index?

Final consistency of MESI cache in CPU -- why does CPU need cache

Use classname to modify style properties

Maximum entropy model

Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference

Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
![After listening to the system clear message notification, Jerry informed the device side to delete the message [article]](/img/0c/52816b75eb702c7c63966578ab4969.jpg)
After listening to the system clear message notification, Jerry informed the device side to delete the message [article]

Do you know the eight signs of a team becoming agile?

MySQL advanced SQL statement (1)

Yyds dry goods inventory override and virtual of classes in C
随机推荐
Huawei rip and BFD linkage
Small program graduation project based on wechat reservation small program graduation project opening report reference
Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends
2020-12-02 SSM advanced integration Shang Silicon Valley
Push technology practice | master these two tuning skills to speed up tidb performance a thousand times!
mysql使用視圖報錯,EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
[turn] solve the problem of "RSA public key not find" appearing in Navicat premium 15 registration
Openbionics exoskeleton project introduction | bciduino community finishing
Final consistency of MESI cache in CPU -- why does CPU need cache
Example 073 square sum value judgment programming requires the input of a and B, if a ²+ b ² If the result of is greater than 100, a is output ²+ b ² Value, otherwise output the result of a + B.
IPv6 experiment
Notice on Soliciting Opinions on the draft of information security technology mobile Internet application (APP) life cycle security management guide
Mongodb learning notes: command line tools
1189. Maximum number of "balloons"
Jerry's update contact [article]
Make drop-down menu
SRCNN:Learning a Deep Convolutional Network for Image Super-Resolution
51 single chip microcomputer timer 2 is used as serial port
JVM performance tuning and practical basic theory - medium
Solution of cursor thickening