当前位置:网站首页>2022acm summer training weekly report (IV)
2022acm summer training weekly report (IV)
2022-07-27 13:41:00 【Eloi0424】
Catalog
22.07.26 Monday
" Weilai cup "2022 Niuke summer multi school training camp 3
J Journey
shortest path 01BFS
The question : n A cross entrance Turn right and it will be green All other turns are red
Ask you from the road s1->s2 To t1->t2 Minimum number of red lights
Ideas : It's just a way of Roads as nodes run 01BFS Just go
Note that it is troublesome to build a map here , You can number the road .
Open one at each intersection map To determine the label of the corresponding road
Code :
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <bitset>
#include <queue>
#include <cstdio>
#include <map>
#include <algorithm>
#include <stack>
// #include <random>
using namespace std;
#define int128 __int128_t
typedef long long ll;
// #define ll int
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
struct triplet
{
ll first, second, third;
};
const ll INF = 1e9;
const ll MAXN = 2e6 + 5;
const ll MOD = 998244353;
const ll Base = 131;
// mt19937_64 mrand(random_device{}());
int n;
int c[5];
map<int,int> num[MAXN];
vector <P> MAP[MAXN];
int dis[MAXN];
bool vis[MAXN];
int s,t;
void BFS()
{
deque <int> q;
q.push_back(s);
dis[s]=0;
while(!q.empty())
{
int from=q.front();
q.pop_front();
if(vis[from])
continue;
vis[from]=1;
for(auto i:MAP[from])
{
int to=i.first,w=i.second;
if(dis[to]>dis[from]+w)
dis[to]=dis[from]+w;
if(w)
q.push_back(to);
else
q.push_front(to);
}
}
}
void solve()
{
cin>>n;
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=4;j++)
cin>>c[j];
for(int j=1;j<=4;j++)
{
if(c[j]==0)
continue;
if(!num[c[j]].count(i))
{
cnt++;
num[c[j]][i]=cnt;
}
if(!num[i].count(c[j%4+1]))
{
cnt++;
num[i][c[j%4+1]]=cnt;
}
MAP[num[c[j]][i]].push_back(P(num[i][c[j%4+1]],0));
for(int k=1;k<=4;k++)
{
if(k!=j%4+1)
{
if(!num[i].count(c[k]))
{
cnt++;
num[i][c[k]]=cnt;
}
MAP[num[c[j]][i]].push_back(P(num[i][c[k]],1));
}
}
}
}
int s1,s2,t1,t2;
cin>>s1>>s2>>t1>>t2;
s=num[s1][s2];
t=num[t1][t2];
for(int i=1;i<=cnt;i++)
dis[i]=1e9;
BFS();
if(dis[t]==1e9)
cout<<-1;
else
cout<<dis[t];
}
int main()
{
// freopen("Test_File\\Test.in", "r", stdin);
// freopen("Test_File\\My_code.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
// int T;
// cin >> T;
// while (T--)
solve();
return 0;
}
// Code By Eloi
21.12.14 Tuesday
21.12.15 Wednesday
22.7.14 Thursday
22.7.15 Friday
23.7.17 Saturday
22.7.18 Sunday
边栏推荐
- Redis总结:缓存雪崩、缓存击穿、缓存穿透与缓存预热、缓存降级
- Fixed positioning
- leetcode——83,24; Machine learning - neural networks
- v-text
- Tools and methods - online flow chart drawing
- [300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (IX)
- Construction and application of industrial knowledge atlas (I): overview of industrial knowledge atlas
- How about the strength of database HTAP
- Seata's landing practice in ant International Banking
- Double material first!
猜你喜欢

3D laser slam:aloam---ceres optimization part and code analysis

SCI thesis writing

电滑环的常用类型

纵横靶场-图片的奥秘
![52: Chapter 5: developing admin management services: 5: developing [paging query admin account list, interface]; (swagger's @apiparam(), annotate the method parameters; PageHelper paging plug-in; Inte](/img/08/1cc315d568673a3892c20bc1254d38.png)
52: Chapter 5: developing admin management services: 5: developing [paging query admin account list, interface]; (swagger's @apiparam(), annotate the method parameters; PageHelper paging plug-in; Inte

How to pass parameters in JNI program

Network packet loss, network delay? This artifact helps you get everything done!

Verilog's system tasks - $fopen, $fclose and $fddisplay, $fwrite, $fstrobe, $fmonitor

How to fix the slip ring

Musk was exposed to be the founder of Google: he broke up his best friend's second marriage and knelt down to beg for forgiveness
随机推荐
Product manager experience 100 (XI) - Strategic Product Manager: model and methodology
《C语言》函数栈帧的创建与销毁--(内功)
Verilog的系统任务----$fopen、$fclose和$fdisplay, $fwrite,$fstrobe,$fmonitor
51:第五章:开发admin管理服务:4:开发【新增admin账号,接口】;(只开发了【用户名+密码的,方式】;【@T…】注解控制事务;设置cookie时,是否需要使用URLEncoder去编码;)
Seata 在蚂蚁国际银行业务的落地实践
egg-swagger-doc 图形验证码解决方案
剑指Offer 07 重建二叉树 -- 从中序与后序遍历序列构造二叉树
【C语言入门】ZZULIOJ 1021-1025
滑环使用如何固定
Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
QT excellent open source project 13: qscintilla
52:第五章:开发admin管理服务:5:开发【分页查询admin账号列表,接口】;(Swagger的@ApiParam(),对方法参数进行注释;PageHelper分页插件;拦截器拦截检查登录状态)
产品经理经验谈100篇(十一)-策略产品经理:模型与方法论
Relative positioning
利用eBPF探测Rootkit漏洞
Perfect guide | how to use ODBC for agent free Oracle database monitoring?
7.26 simulation summary
浏览器内核模块组成
How to fix the slip ring
How to maintain slip ring equipment