ch6
紫书第6章
蹲坑看手机
已搬家
展开
-
UVA1600 Patrol Robot(BFS)
title: “UVA1600”date: 2020-08-03T16:26:13+08:00draft: truecategories: [“紫书刷题录-ch6”]tags: [“题解”, “图”]description: “description.”本题vjudge链接BFS进阶题题意:有个移动的机器人,从(1, 1)点出发,目标是(m, n)点,0为可以通过的点,1为障碍点,机器人一次最多只能穿越k障碍,问你最少要走多少步到达终点BFS走,要注意个是要记录到达障碍点的最短穿越障碍.原创 2020-08-13 14:26:23 · 114 阅读 · 0 评论 -
UVA839 Not so Mobile
title: “UVA839”date: 2020-07-31T17:53:32+08:00draft: truecategories: [“紫书刷题录-ch6”]tags: [“题解”, “树”]description: “description.”本题vjudge链接题意:天平平衡,题意很好懂,就是让你判断给的天平平不平衡,直接递归读入就好了#include <bits/stdc++.h>using namespace std;int t, w;bool ok.原创 2020-08-13 14:25:16 · 114 阅读 · 0 评论 -
UVA12166 Equilibrium Mobile(二叉树)
title: “UVA12166”date: 2020-08-03T20:27:46+08:00draft: truecategories: [“紫书刷题录-ch6”]tags: [“题解”, “树”, “思维”]description: “description.”本题vjudge链接题意:给你一个天平,修改某些节点可以使得天平平衡,让你求出最小的修改数量竟然是一道思维题,不行,这题要写写题解思路:假设这个数是一个满二叉树的,并且每个叶子节点每个叶子节点的重量(权值)都不一样,则.原创 2020-08-12 09:26:34 · 180 阅读 · 0 评论 -
UVA10410 Tree Reconstruction
title: “UVA10410”date: 2020-08-05T10:12:16+08:00draft: truecategories: [“紫书刷题录-ch6”]tags: [“题解”, “树”]description: “description.”本题vjudge链接题意:给你一个DFS和一个BFS遍历的树(具体遍历方式都是小的权值优先),让你求出每个节点的子节点直接说思路:栈的运用,题目说输出任意可能的答案,所以把树当成一个二叉树来做,bfs本质就是树的一层一层的遍历,当一个节.原创 2020-08-12 09:26:00 · 87 阅读 · 0 评论 -
UVA10305 Ordering Tasks(拓扑排序)
title: “UVA10305”date: 2020-08-01T09:47:35+08:00draft: truetags: [“题解”, “图”, “拓扑排序”]description: “description.”本题vjudge链接题意:给你一堆未知数的大小关系,让你输出可能的总体大小关系简化了拓扑排序,只因根据题中的意思了解到一定是DAG#include <bits/stdc++.h>using namespace std;const int M = 1.原创 2020-08-12 09:25:13 · 124 阅读 · 0 评论 -
UVA816 Abbott‘s Revenge(BFS)
title: “UVA816”date: 2020-08-01T15:56:21+08:00draft: truetags: [“题解”, “图”]description: “description.”本题vjudge链接题意:给你起点和终点,每个点面向不同的方向有不用的指定方向,问你从起点到终点最短路BFS就好,但是要注意的是每个点都有不用的方向,所以要多加一维来保存这些方向,即每个点相当于是4个点一道值得学习深究的一题#include <bits/stdc++.h>.原创 2020-08-12 09:24:28 · 122 阅读 · 0 评论 -
UVA806 Spatial Structures(树)
title: “UVA806”date: 2020-08-04T18:02:01+08:00draft: truecategories: [“紫书刷题录-ch6”]tags: [“题解”, “树”]description: “description.”本题vjudge链接类似于计算像素的,读懂题意直接模拟就好了毒瘤题#include <bits/stdc++.h>using namespace std;using ll = long long;int n, kas.原创 2020-08-12 09:23:45 · 101 阅读 · 0 评论 -
UVA804 Petri Net Simulation(模拟)
title: “UVA804”date: 2020-08-04T14:26:40+08:00draft: truecategories: [“紫书刷题录-ch6”]tags: [“题解”, “图”, “模拟”]description: “description.”本题vjudge链接每个T变迁都有限制,必须是指定的P库有足够的token才行(注意,T指定的P库不一定只有一个),直接模拟就好了#include <bits/stdc++.h>using namespace .原创 2020-08-12 09:23:11 · 149 阅读 · 0 评论 -
UVA712 S-Trees(二叉树)
title: “UVA712”date: 2020-08-02T14:41:02+08:00draft: truecategories: [“紫书刷题录-ch6”]tags: [“题解”, “树”]description: “description.”本题vjudge链接题意:一棵二叉树,每个层节点都有有个逻辑布尔变量,0往左走,1往右走,给你最后一层的结果值,再给你每个变量的取值,问你最后走到的最后一层叶子节点的值这题有点迷,一开始忘记记录变量的顺序尽然也过了,后来记录了也能过不考虑.原创 2020-08-12 09:22:19 · 155 阅读 · 0 评论 -
UVA699 The Falling Leaves(二叉树)
title: “UVA699”date: 2020-07-31T19:38:47+08:00draft: truecategories: [“紫书刷题录-ch6”]tags: [“题解”, “树”]description: “description.”本题vjudge链接二叉树的计算,直接递归读入遍历即可所有数据要以空行相隔,UVA特色#include <bits/stdc++.h>using namespace std;const int M = 5e5;in.原创 2020-08-12 09:21:15 · 85 阅读 · 0 评论 -
UVA679 Dropping Balls(二叉树)
本题vjudge链接题意:小球在一个二叉树上下落,每个节点都有一个开关,起初全是关的,如果节点是开小球往右走,反之往左走,让你求最后一个球落到了哪个节点如果直接单纯的模拟是会超时的,观察可以发现一个节点的第奇数个球都会落到左子树,第偶数个球都落到了右边,自己草稿模拟一下就好了代码如下#include <bits/stdc++.h>using namespace std;int d, n, t;int main() {#ifndef ONLINE_JUDGE fr原创 2020-08-12 09:20:02 · 83 阅读 · 0 评论 -
UVA672 Parentheses Balance(栈)
本题vjudge链接让你判断括号是否合法,栈的经典例题#include <bits/stdc++.h>using namespace std;int t;int main () {#ifndef ONLINE_JUDGE freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);#endif scanf("%d", &t); getchar(); whi原创 2020-08-12 09:18:18 · 82 阅读 · 0 评论 -
UVA572 Oil Deposits(dfs)
本题vjudge链接给你一个矩形图,让你求连通的“@”块,一个连通的定义是该点的八个方向都是连通的,dfs就行了#include <bits/stdc++.h>using namespace std;int m, n, cont[110][110];char g[110][110];void dfs(int x, int y, int num) { if (x < 0 || y < 0 || x >= m || y >= n || cont[原创 2020-08-11 14:14:10 · 125 阅读 · 1 评论 -
UVA548 Tree(树)
本题vjudge链接给你二叉树的中序和先序遍历,让你求从根节点到叶节点的的距离权值和最小,如果有多解,叶节点的权值要小,输出叶节点的权值#include <bits/stdc++.h>using namespace std;const int M = 1e4 + 10;string str;int ino[M], posto[M], ans, Max, lson[M], rson[M], len = 0;void dfs(int u, int sum) { if原创 2020-08-11 14:11:21 · 315 阅读 · 0 评论 -
UVA536 Tree Recovery(树)
本题vjudge链接给你一个二叉树的先序和中序遍历,输出对应的后序遍历#include <bits/stdc++.h>using namespace std;char pre[30], in[30];void dfs(int a, int b, int c, int d) { if (c > d) return; char tmp = pre[a]; int indx = c; while (in[indx] != tmp) indx+原创 2020-08-11 14:08:51 · 88 阅读 · 0 评论 -
UVA514 Rails(栈)
本题vjudge链接让你判断列车出站是否正确,栈的运用#include <algorithm>#include <cstdio>#include <cstring>#include <stack>using namespace std;const int M = 1e3 + 10;int n, arr[M];int main() {#ifndef ONLINE_JUDGE freopen("test.in", "r", s原创 2020-08-11 14:05:46 · 110 阅读 · 0 评论 -
UVA442 Matrix Chain Multiplication (栈)
本题vjudge链接#include <bits/stdc++.h>using namespace std;using pii = pair<int, int>;int n;pii m[30];char str[100000];int main() {#ifndef ONLINE_JUDGE freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);#endif sc原创 2020-08-11 11:38:48 · 165 阅读 · 0 评论 -
UVA439 Knight Moves(BFS)
UVA439 Knight Movesvjudge链接#include <bits/stdc++.h>#define mk(a, b) make_pair(a, b)using namespace std;using pii = pair<int, int>;using pdi = pair<pii, int>;int sx, sy, ex, ey;bool vis[10][10];char a[5], b[5];const int dx[] = {原创 2020-08-11 11:25:36 · 95 阅读 · 0 评论 -
UVA122 Trees on the level(二叉树)
UVA122Trees on the level#include <bits/stdc++.h>using namespace std;const int M = 1e5 + 10;int lson[M], rson[M], cnt, node[M];bool ok, in[M] = {false};//in记录节点是否存在vector<int> ans;int newnode() {//申请新的地址 int u = ++cnt; lson[u原创 2020-08-11 11:15:03 · 157 阅读 · 1 评论