当前位置:网站首页>Explanation of the second I interval of 2020 Niuke summer multi school training camp
Explanation of the second I interval of 2020 Niuke summer multi school training camp
2022-04-23 06:29:00 【cornivores】
2020 The second session of Niuke summer multi school training camp I Interval
The question : For interval [l, r] There are two operations , The first is to reduce the interval , Turn it into [l+1,r] perhaps [l,r+1], The second is the expansion interval , Turn it into [l-1,r] perhaps [l,r+1], There are two blocking operations (l,r,dir,c), The first one is dir='L’ You can make [l,r] Don't become [l+1,r], The second kind dir='R’ You can make [l,r] Don't become [l,r-1], The cost is c. The starting point is [1,n], Make it impossible to reach during operation [i,i] In the form of , Ask what the minimum cost is .
solution : First of all, this is a grid diagram , The starting point is the upper right corner , The end point is the point on the diagonal , To make the starting point unable to reach the end , Some blocking operations , It's equivalent to cutting off some edges , So how to build an edge for the example , Look at the picture .
3 4
1 3 L 10
1 3 R 3
1 2 L 1
1 2 R 1
In fact, it is to establish super source and super sink , Then the meaning of each edge is to cut off this edge , Up here s To t Just run the shortest way . The thought applied is the thought of minimum cut , A wolf catching a rabbit is very similar to this question , But it seems that the author of the question has lost the practice of seeking the minimum cut , I ISAP Constant segment error .
Code :
#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-8
#define rint register int
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
int f = 1; res = 0;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1; c = getchar(); }
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0'; c = getchar(); }
res *= f;
}
const int ne[8][2] = {
1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const LL INF = 1e15;
const int N = 3e5+10;
const LL Mod = 1234567891;
const int M = 2e6+10;
struct xx {
int next, to; LL w;
xx() {
}
xx(int next, int to, LL w) {
this->next = next; this->to = to; this->w = w;
}
}e[M];
int tot, head[N];
void Add(int u, int v, LL w) {
e[++tot] = xx(head[u], v, w);
head[u] = tot;
e[++tot] = xx(head[v], u, w);
head[v] = tot;
}
int s, t, u, v;
priority_queue<pli, vector<pli>, greater<pli> > q;
LL dis[N], vis[N];
void dij() {
for(int i = 0; i <= t; ++i) dis[i] = INF, vis[i] = 0;
dis[s] = 0; q.push(make_pair(dis[s], s));
while(!q.empty()) {
u = q.top().second; q.pop();
if(vis[u]) continue;
vis[u] = 1;
for(int i = head[u]; i; i = e[i].next) {
v = e[i].to;
if(dis[v] > dis[u] + e[i].w) {
dis[v] = dis[u] + e[i].w;
q.push(make_pair(dis[v], v));
}
}
}
}
int n, m;
int main() {
scanf("%d%d", &n, &m);
int x, y; char dir; LL c;
int u, v;
s = 0; t = n*n+1;
for(int i = 0; i < m; ++i) {
scanf("%d %d %c %lld", &x, &y, &dir, &c);
u = (x-1)*n + y;
if(dir == 'R') v = max(s, u-n);
else v = u, u = (y == n ? t : v + 1);
Add(u, v, c);
}
dij();
if(dis[t] >= INF) puts("-1");
else printf("%lld\n", dis[t]);
return 0;
}
版权声明
本文为[cornivores]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210615591701.html
边栏推荐
- Optional best practices
- How does MySQL convert stored seconds into dates
- Busybox initrd and initialization process
- Exception handling: grab and throw model
- Kalman filter and inertial integrated navigation
- 檢測技術與原理
- Preparedstatement prevents SQL injection
- 基于pygame库编写的五子棋游戏
- SQL -- data filtering and grouping
- Animation - Introduction to keyframes
猜你喜欢
Robocode教程3——Robo机器剖析
Motor and drive (Qi Jinqing Edition)
Explain of MySQL optimization
Contrôle automatique (version Han min)
How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation
-- SQL query and return limit rows
In depth source code analysis servlet first program
Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code
Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
Techniques et principes de détection
随机推荐
RPC must know and know
Problems and solutions of database migration
LockSupport. Park and unpark, wait and notify
Substring Inversion (Easy Version)
Code neat way to learn
Collection and map thread safety problem solving
Consistent hash algorithm used for redis cache load balancing
Introduction to virtualization features
H. Are You Safe? Convex hull naked problem
Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
Contrôle automatique (version Han min)
Complete example demonstration of creating table to page - joint table query
Rainbow (DP)
基于pygame库编写的五子棋游戏
What is the difference between the basic feasible solution and the basic feasible solution in linear programming?
9.Life, the Universe, and Everything
Usage scenario of copyonwritearraylist
6.Reversal
C # Foundation
Techniques et principes de détection