当前位置:网站首页>Niuke multi school -journey- (map building distra+ card often optimization)
Niuke multi school -journey- (map building distra+ card often optimization)
2022-07-26 21:22:00 【Lovely and beautiful girl】
The question :
It's for you. n A crossroads , There are four directions at each intersection , Mark your intersection counterclockwise , If it is 0 The sign means there is no intersection . Then every time you turn right at the intersection, it doesn't cost , And move on , Turn left , Overturn , It's all cost 1. First, you are A The intersection faces B On the road at the intersection , Let you walk to C The intersection faces D On the road at the intersection . Ask you the least cost . The direction you face is unnecessary ,A Yes B and B Yes A It's different .
reflection :
In fact, this question , Give you the intersection , I didn't give you a designated direction , Just in reverse order . If you run the shortest way at the intersection, you will find this diagram difficult to get . So run by the side , That is, regard the edge as a point , Look at these edges as different points , Conduct hash. How did you think of it , Because it's about the cost of walking from one road to another , So it's easier to take the road as a point . When building a map, it is to enumerate four intersections of an intersection , Then find two intersections , Build a map for them , If it's a right turn, it doesn't cost .
Then it is worth noting that , use map<PII,int> Hash will timeout , Then change to unordered_map<PII,int,cmp>. This cmp Overload usage is different, there will be timeout and no timeout . Of course, the safest thing is not to build a map , Run straight , Just enumerate where you go when you run . When hashing, hash the edge into a particularly large value and put it in unordered_map<int,int> That's all right. .
Code :
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define db double
#define int long long
#define PII pair<int,int >
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int mod = 1e9+7,inf = 1e18;
const int N = 5e6+10,M = 2010;
int T,n,m,k;
int va[N][4];
int dist[N],vis[N];
struct cmp{
int operator()(PII A)const{
return A.fi*521417+A.se;
}
};
int cnt;
unordered_map<PII,int,cmp> mp;
vector<PII > e[N];
void distra(int A)
{
for(int i=1;i<=cnt;i++) dist[i] = inf;
priority_queue<PII,vector<PII>,greater<PII> > q;
q.push({
0,A});
dist[A] = 0;
while(q.size())
{
auto t = q.top();q.pop();
int now = t.se,dis = t.fi;
if(vis[now]) continue;
for(auto tt:e[now])
{
int spot = tt.fi,w = tt.se;
if(dist[spot]>dist[now]+w)
{
dist[spot] = dist[now]+w;
q.push({
dist[spot],spot});
}
}
}
}
signed main()
{
IOS;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=0;j<4;j++)
{
cin>>va[i][j];
if(!va[i][j]) continue;
int a = i,b = va[i][j];
if(!mp[{
a,b}]) mp[{
a,b}] = ++cnt;
if(!mp[{
b,a}]) mp[{
b,a}] = ++cnt;
}
for(int j=0;j<4;j++)
{
if(!va[i][j]) continue;
for(int k=0;k<4;k++)
{
if(!va[i][k]) continue;
int a = va[i][j],b = i,c = va[i][k],w = 1;
if((j+1)%4==k) w = 0;
int x = mp[{
a,b}],y = mp[{
b,c}];
e[x].pb({
y,w});
}
}
}
int A,B,C,D;
cin>>A>>B>>C>>D;
distra(mp[{
A,B}]);
if(dist[mp[{
C,D}]]==inf) cout<<-1;
else cout<<dist[mp[{
C,D}]];
return 0;
}
summary :
Try more , I feel map When it doesn't work ,unordered Not good either. , I don't want to write . Little by little optimization , Maybe it's over in the end .
边栏推荐
- Flash source code outline
- 2022-7-26 第七组 抽象和接口
- PointPillars: Fast Encoders for Object Detection from Point Clouds 阅读笔记
- 腾讯为什么没能造创造出《原神》这样的游戏
- DeepFake捏脸真假难辨,汤姆·克鲁斯比本人还像本人!
- 2022 pole technology communication - anmou technology opens a new chapter of commercialization
- 牛客多校-Journey-(建图distra+卡常优化)
- QT Foundation Day 1 (1) QT, GUI (graphical user interface) development
- 传奇GEE引擎版本如何封挂?通过脚本+引擎封玩家账号教程
- 微服务化解决文库下载业务问题实践
猜你喜欢

【虚拟机数据恢复】意外断电导致XenServer虚拟机不可用的数据恢复

【HarmonyOS议题资料下载】HDD杭州站·线下沙龙专注应用创新 展现鸿蒙生态魅力

一些意想不到的bug记录

7-year-old boy playing chess too fast? The robot actually broke its finger

微服务化解决文库下载业务问题实践

2022-7-26 the seventh group of abstractions and interfaces

What is the function of the serializable interface?

Interceptors

和月薪3W的字节程序员聊过后,才知道自己一直在打杂...

Summary of 4 years of software testing experience and interviews with more than 20 companies after job hopping
随机推荐
idea中检索此方法中有哪些参数以便我们使用——1.类图。2.双击shift
[英雄星球七月集训LeetCode解题日报] 第26日 并查集
腾讯为什么没能造创造出《原神》这样的游戏
Monitor MySQL based on MySQL exporter
【HCIA安全】用户认证
In addition to "adding machines", in fact, your micro service can be optimized like this
【HCIA安全】NAT网络地址转换
修改excel默认编码
LiveDatade的基本使用
7-year-old boy playing chess too fast? The robot actually broke its finger
HTTP cache browser cache that rabbits can understand
SPI配置
Modify excel default code
2022 pole technology communication - anmou technology opens a new chapter of commercialization
Daily practice ----- there is a group of students' grades. Arrange them in descending order. To add a student's grade, insert it into the grade sequence and keep the descending order
Flutter Performance Optimization Practice - UI chapter
Introduction of JDBC
[download materials of harmoniyos topics] HDD Hangzhou station · offline salon focuses on application innovation to show the ecological charm of Hongmeng
Rare discounts on Apple's official website, with a discount of 600 yuan for all iphone13 series; Chess robot injured the fingers of chess playing children; Domestic go language lovers launch a new pro
GOM login configuration free version generate graphic tutorial