前言

I hate questions that already exist!!

我讨厌原题!!

赛时得分明细:

A B C D E F Total Rank
100 100 10 56 0 44 310 6

A. P1993 小 K 的农场

题面

给定长度为 \(n\) 的数组 \(A_1,A_2,A_3,\dots,A_n\) 和 \(m\) 个约束条件,约束条件有三种:

  • \(1\) \(x\) \(y\) \(c\) :\(A_x - A_y \ge c\);
  • \(2\) \(x\) \(y\) \(c\) :\(A_x - A_y \le c\);
  • \(3\) \(x\) \(y\) :\(A_x = A_y\);

输出是否存在合法的自然数解。存在输出 "\(Yes\)", 不存在输出 "\(No\)"。

\(1 \le n,m \le 5 \times 10^3\)

题解

差分约束模板

可以尝试把 \(A_x - A_y \ge c\) 转化为 \(A_y \le A_x - c\),把 \(A_x - A_y \le c\) 转化为 \(A_x \le A_y + c\)。

\(A_x = A_y\) 可以转化为 \(A_x - A_y = 0\),进而变成 \(A_x - A_y \le 0\) 且 \(A_x - A_y \ge 0\)。

每次遇到一个约束条件就将建 \(5\) 条边:

  1. \(x \to y\),权值为 \(-w\);
  2. \(y \to x\),权值为 \(w\);
  3. \(x \to y\),权值为 \(0\);
  4. \(y \to x\),权值为 \(0\);

建一个超级点,跑最短路即可。但不能用 \(dijkstra\),因为存在负环(或是要判负环)。

代码

#include <bits/stdc++.h>
#define int long long
#define H 19260817
#define rint register int
#define For(i,l,r) for(rint i=l;i<=r;++i)
#define FOR(i,r,l) for(rint i=r;i>=l;--i)
#define MOD 1000003
#define mod 1000000007 using namespace std; inline int read() {
rint x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*f;
} void print(int x){
if(x<0){putchar('-');x=-x;}
if(x>9){print(x/10);putchar(x%10+'0');}
else putchar(x+'0');
return;
} const int N = 1e6 + 10; struct Node {
int v, w;
}; int n, m, q[N], dist[N], cnt[N]; bool st[N]; vector <Node> e[N]; bool spfa() {
int h = 1, t = 0;
memset(dist, 0x3f, sizeof dist);
memset(st, 0, sizeof st);
memset(cnt, 0, sizeof cnt);
q[++t] = 0, st[0] = 1, dist[0] = 0;
while(h <= t) {
int x = q[h++];
st[x] = 0;
for (int i = 0; i < e[x].size(); i++) {
int y = e[x][i].v, w = e[x][i].w;
if(dist[y] > dist[x] + w) {
dist[y] = dist[x] + w;
cnt[y] = cnt[x] + 1;
if(cnt[y] >= n + 1) return 0;
if(!st[y]) {
q[++t] = y;
st[y] = 1;
}
}
}
}
return 1;
} void add(int u, int v, int w) {
e[u].push_back((Node){v, w});
} signed main() {
n = read(), m = read();
For(i,1,m) {
int op = read(), x = read(), y = read();
if(op == 1) {
int w = read();
add(x, y, -w);
} else if(op == 2) {
int w = read();
add(y, x, w);
} else {
add(x, y, 0);
add(y, x, 0);
}
}
For(i,1,n) add(0, i, 0);
puts(spfa()?"Yes":"No");
return 0;
}

B. P2294 [HNOI2005]狡猾的商人

题面

对于一个长度为 \(n\) 的数组,给定 \(m\) 个部分和 \(\sum_{l=1}^{r} A_i\),判断该数组是否合法(合法输出 "\(Yes\)",不合法输出 "\(No\)")。

题解

代码

#include <bits/stdc++.h>
#define int long long
#define H 19260817
#define rint register int
#define For(i,l,r) for(rint i=l;i<=r;++i)
#define FOR(i,r,l) for(rint i=r;i>=l;--i)
#define MOD 1000003
#define mod 1000000007 using namespace std; inline int read() {
rint x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*f;
} void print(int x){
if(x<0){putchar('-');x=-x;}
if(x>9){print(x/10);putchar(x%10+'0');}
else putchar(x+'0');
return;
} const int N = 2e5 + 10; int n, m, Q, f[N], val[N]; int find(int x) {
if(x == f[x]) return x;
else {
int root = find(f[x]);
val[x] += val[f[x]];
return f[x] = root;
}
} signed main() {
Q = read();
while(Q--) {
bool vis = 0;
n = read(), m = read();
For(i,0,n) f[i] = i, val[i] = 0;
For(i,1,m) {
int l = read(), r = read(), s = read();
l--;
int t1 = find(l), t2 = find(r);
if(t1 != t2) {
f[t2] = t1;
val[t2] = val[l] + s - val[r];
} else {
if(val[r] - val[l] != s) {
vis = 1;
puts("false");
break;
}
}
}
if(!vis) puts("true");
}
return 0;
}

C. P7624 [AHOI2021初中组] 地铁

题面

题解

代码

D. P6378 [PA2010] Riddle

题面

题解

代码

E. P3513 [POI2011] KON-Conspiracy

题面

题解

代码

F. P5905 【模板】Johnson 全源最短路

题面

题解

代码

test20230225考试总结(2023春 · 图论)的更多相关文章

  1. test20230111考试总结 -2023寒图论专题

    前言 赛时得分情况: A B C D E F G H I \(\texttt{Total}\) \(\texttt{Rank}\) \(100\) \(100\) \(10\) \(58\) \(54 ...

  2. test20230109考试总结-2023寒搜索专题

    前言 2023 年的第一篇考试总结-- 赛时得分情况: A B C D E F G \(\texttt{Total}\) \(\texttt{Rank}\) \(40\) \(80\) \(0\) \ ...

  3. DP&图论 DAY 6 下午 考试

    DP&图论  DAY 6  下午  考试 样例输入 样例输出 题解 >50 pt      dij 跑暴力 (Floyd太慢了QWQ    O(n^3)) 枚举每个点作为起点,dijks ...

  4. 躬身入局,干货分享,2023年春招后端技术岗(Python)面试实战教程,Offer今始为君发

    早春二月,研发倍忙,杂花生树,群鸥竟飞.为什么?因为春季招聘,无论是应届生,还是职场老鸟,都在摩拳擦掌,秣马厉兵,准备在面试场上一较身手,既分高下,也决Offer,本次我们打响春招第一炮,躬身入局,让 ...

  5. 2023年2月份CKA考试历程

    2023年2月份CKA 考试历程 目录 2023年2月份CKA 考试历程 一.购买CKA/CKS套餐 二.CKA 考试练习 三.CKA 第一次考试 考前考中 考后 四.CKA 第二次考试 五.考试的一 ...

  6. 2019年春PAT甲级考试

    这次考试不是很理想,一道题目没能做完. 自己原因差不多三条: 1.自己实力不够,准备时间也有点仓促,自己没能做到每道题目都有清晰的思路. 2.考试的心理素质不行,因为设备原因东奔西跑浪费了挺多时间,自 ...

  7. 图论专题1考试Problem1

    Problem 1. bricksInput file: bricks.inOutput file: bricks.outTime limit: 1 secondjyb 在BUAA 天天被大神虐,所以 ...

  8. 链家2018春招C/C++开发实习生在线考试编程题

    题目一 题解:该题目意思就是让你输入n组数据,然后求并集,利用STL容器set集合的特性:元素不重复存储,我们可以很轻易得出答案 #include <iostream> #include ...

  9. 【洛谷2019 OI春令营】期中考试

    T68402 扫雷 题目链接:传送门 题目描述 扫雷,是一款单人的计算机游戏.游戏目标是找出所有没有地雷的方格,完成游戏:要是按了有地雷的方格,游戏失败.现在 Bob 正在玩扫雷游戏,你作为裁判要判断 ...

  10. DP&图论 DAY 3 下午 考试

    Problem AProblem Description有一天 Tarzan 写了一篇文章,我们发现这文章当中一共出现了 n 个汉字,其中第 i 个汉字出现了 ai 次,因为 Tarzan 不希望文章 ...

随机推荐

  1. Django笔记三十四之分页操作

    本文首发于公众号:Hunter后端 原文链接:Django笔记三十四之分页操作 这一篇笔记介绍一下如何在 Django 使用分页. Django 自带一个分页的模块: from django.core ...

  2. Unity中实现字段/枚举编辑器中显示中文(中文枚举、中文标签)

    在unity开发编辑器相关经常会碰到定义的字段显示在Inspector是中文,枚举也经常碰到显示的是字段定义时候的英文,程序还好,但是如果编辑器交给策划编辑,策划的英文水平不可保证,会很头大,所以还是 ...

  3. 【Python基础】数据类型与类型转换

    五种基本数据类型 在 Python 中,基本数据类型是指不可变对象的数据类型.以下是 Python 中的基本数据类型: 整数类型(int):表示整数,例如 1.2.3 等等. 浮点数类型(float) ...

  4. 2022-10-18:以下go语言代码输出什么?A:panic;B:编译错误;C:moonfdd1。 package main import ( “fmt“ “net/url“ ) // 其中

    2022-10-18:以下go语言代码输出什么?A:panic:B:编译错误:C:moonfdd1. package main import ( "fmt" "net/u ...

  5. 【GiraKoo】常用编码的对比(ASCII,GB2312,GBK,GB18030,UCS,Unicode)

    常用编码的对比(ASCII,GB2312,GBK,GB18030,UCS,Unicode) 在程序开发中,文字编码一直扮演着人畜无害,却背后捅一刀的角色. 可能在源代码文件中,注释莫名其妙地变成了乱码 ...

  6. Typo in static class property declarationeslint

    eslint 检测提示 Typo in static class property declarationeslint 找了半天原来是propTypes 写成了PropTypes (就是一个首字母大写 ...

  7. django 如何提升性能(高并发)

    django 如何提升性能(高并发) 对一个后端开发程序员来说,提升性能指标主要有两个一个是并发数,另一个是响应时间网站性能的优化一般包括 web 前端性能优化,应用服务器性能优化,存储服务器优化. ...

  8. Spring 核心概念之一 IoC

    前言 欢迎来到本篇文章!通过上一篇什么是 Spring?为什么学它?的学习,我们知道了 Spring 的基本概念,知道什么是 Spring,以及为什么学习 Spring.今天,这篇就来说说 Sprin ...

  9. Kubernetes 1.27.2集群安装

    基础环境 系统Ubuntu 22.04.2 | 主机名称 | IP | | ----- | -------- | | k8s-master | 192.168.198.141 | | k8s-node ...

  10. docker安装LuaJIT WEB应用防火墙

    安装包请见 https://www.jianshu.com/p/b81656764613 Dockerfile #FROM ubuntu FROM centos MAINTAINER G00G1S C ...