当前位置:网站首页>2022ACM夏季集训周报(四)
2022ACM夏季集训周报(四)
2022-07-27 12:52:00 【Eloi0424】
目录
22.07.26 Monday
"蔚来杯"2022牛客暑期多校训练营3
J Journey
最短路 01BFS
题意: n 个十字入口 右转必为绿灯 其他转向都为红灯
问你从道路 s1->s2 到 t1->t2 的最少红灯数
思路:其实就是把 道路当作节点 跑01BFS就行
注意这里建图很麻烦,可以给道路标序号。
对每个十字路口开一个map来确定对应道路的标号
代码:
// #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
边栏推荐
- 绝对定位
- Write a program, accept a string consisting of letters, numbers and spaces, and a character, and then output the number of characters in the input string. Case insensitive.
- Application of responsibility chain model in transfer accurate valuation
- Height collapse and BFC
- Getting started for beginners: build your own blog with WordPress
- 数据库HTAP能力强弱怎么看
- Verilog的系统任务----$fopen、$fclose和$fdisplay, $fwrite,$fstrobe,$fmonitor
- Talk about one of the important classes of feign components, reactivefeign
- 16-VMware Horizon 2203 虚拟桌面-Win10 自动桌面池完整克隆专用(十六)
- Absolute positioning
猜你喜欢

力扣 1480. 一维数组的动态和 383. 赎金信412. Fizz Buzz

Li Kou 1480. Dynamic sum of one-dimensional array 383. Ransom letter 412. Fizz buzz

马斯克被曝绿了谷歌创始人:导致挚友二婚破裂,曾下跪求原谅

js将数组根据指定属性值分组成二维数组

W3School导航栏练习

MFC FTP creates multi-level folders and uploads files to the specified directory of FTP

v-text

Interviewers often ask: how to set up a "message queue" and "delayed message queue"?

eBPF/Ftrace

52:第五章:开发admin管理服务:5:开发【分页查询admin账号列表,接口】;(Swagger的@ApiParam(),对方法参数进行注释;PageHelper分页插件;拦截器拦截检查登录状态)
随机推荐
字节跳动 AI Lab 总监李航:语言模型的过去、现在和未来
Relative positioning
7.26 simulation summary
How to pass parameters in JNI program
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (IX)
SCI论文写作
A brief analysis of the four process pools
责任链模式在转转精准估价中的应用
Rotation chart
插入排序,正序,倒序
C ftp add, delete, modify, query, create multi-level directory, automatic reconnection, switch directory
Interview site: three kinds of questions
leetcode——83,24; Machine learning - neural networks
The role of Clearfix
初探基于OSG+OCC的CAD之任意多个子模型进行netgen以及gmsh网格划分
Qt优秀开源项目之十三:QScintilla
纵横靶场-图片的奥秘
附加:【URLEncoder.encode(待编码字符串, “编码方式“);】(是什么?;我们向cookie中设置值的时候,为什么要使用这个去编码?)(待完善……)
v-text
Fiddler bag capturing Tool + night God simulator