
图-DFS
文章平均质量分 88
Dave_L
这个作者很懒,什么都没留下…
展开
-
剑指Offer
题目描述在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。每行二分class Solution {public: bool Find(int target, vector<vector<int> > array) ...原创 2019-12-28 14:07:27 · 284 阅读 · 0 评论 -
zoj1084 染色问题 (四色定理or暴力)
Channel AllocationTime Limit: 2 Seconds Memory Limit: 65536 KB When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every rec原创 2018-01-10 10:46:21 · 633 阅读 · 4 评论 -
奇偶剪枝
把矩阵看成如下形式: 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 从为 0 的格子走一步,必然走向为 1 的格子 。从为 1 的格子走一步,必然走向为 0 的格子 。即: 从 0 走向 1 必然是奇数步,从 0 走向 0 必然是偶数步。所以当遇到从 0 走向 0 但是要求时间是奇数的原创 2018-01-19 09:17:28 · 290 阅读 · 0 评论 -
poj1124 Oh, Those Achin' Feet dfs+bfs最短路
Oh, Those Achin' FeetTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 490 Accepted: 131DescriptionIn recent days, a number of people have been injured afte原创 2018-01-14 10:11:21 · 450 阅读 · 0 评论 -
蓝桥- 历届试题 2013-10-19剪格子 搜索
历届试题 剪格子 时间限制:1.0s 内存限制:256.0MB 问题描述如下图所示,3 x 3 的格子中填写了一些整数。+--*--+--+|10* 1|52|+--****--+|20|30* 1|*******--+| 1| 2| 3|+--+--+--+我们沿着图中的星号线剪开,得到两个部分,每个部分的原创 2018-03-13 15:56:10 · 203 阅读 · 0 评论 -
蓝桥- 历届试题 2013-10-19 大臣的旅费
历届试题 大臣的旅费 时间限制:1.0s 内存限制:256.0MB 问题描述很久以前,T王国空前繁荣。为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国内的各大城市。为节省经费,T国的大臣们经过思考,制定了一套优秀的修建方案,使得任何一个大城市都能从首都直接或者通过其他大城市间接到达。同时,如果不重复经过大城市,从首都到达每原创 2018-03-13 16:13:24 · 189 阅读 · 0 评论 -
蓝桥网 历届试题 地宫取宝 dfs记忆化搜索
历届试题 地宫取宝 时间限制:1.0s 内存限制:256.0MB 问题描述 X 国王有一个地宫宝库。是 n x m 个格子的矩阵。每个格子放一件宝贝。每个宝贝贴着价值标签。 地宫的入口在左上角,出口在右下角。 小明被带到地宫的入口,国王要求他只能向右或向下行走。 走过某个格子时,如果那个格子中的宝贝价值比小明手中任意宝贝价原创 2018-03-27 15:32:34 · 242 阅读 · 0 评论 -
Codeforces Round #490 (Div. 3) D. Equalize the Remainders E Reachability from the Capital
E. Reachability from the Capital time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are n n cities and m m roads in Berland. E...原创 2018-07-01 15:30:44 · 292 阅读 · 0 评论 -
Codeforces Round #494 (Div. 3) A , B ,C , D , E
A 略B 题意要求a个0,b个1,有且只有x个位置si 不等于si+1 思路:初始构建一个有x-1个位置si ≠ si+1 的串( 0 多就0开头,1多就1开头) 0多且x为偶数,则初始串结尾一定为0,所以先输出0,在输出1 ,x-1+1 满足x 1多且x为奇数,初始串结尾一定为1,所以先输出0,再输出1.剩下两种情况类似。Code:#include <bits/s...原创 2018-07-04 11:13:07 · 163 阅读 · 0 评论 -
练习赛9
A 签到 Code:#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define LL long longusing namespace std;int main(){ int T; int a , b , c; int one = 0 ; int zero = 0 ; ci...原创 2018-07-26 20:03:59 · 155 阅读 · 0 评论 -
练习赛13 A滑动窗口 B dp+树状数组维护前缀和 C博弈 G dfs序+线段树 H思维 Ifloyd J模拟
B题意:给一个数组,求有多少个严格上升的子序列 思路: dp[i]表示以i结尾的上升子序列个数,dp[i] = Σdp[j] + 1 a[i] &amp;amp;amp;amp;gt; a[j] . 先离散化下,然后用树状数组维护前面比他小的 结果的和 , 每次加1然后更新dp[i],最后询问最大的数(离散化后最大为n)的结果。 Code:#include &amp;amp;amp;amp;lt;bits/stdc++.h&amp;amp;原创 2018-07-31 17:53:02 · 343 阅读 · 0 评论 -
8.3 训练赛补题 B思维 C方格填数(搜索) E枚举,精度
B 思路:相当于转化成b进制。 Code:#include <bits/stdc++.h>#define LL unsigned long long using namespace std;int main(){ int T; cin >> T; LL K , b ,n ; while( T-- ){ cin ...原创 2018-08-11 13:43:48 · 230 阅读 · 0 评论 -
练习赛3 B组合 C multiset D set G 计算几何矩形面积交/并 H模拟 I 组合数公式+逆元 J搜索 K添加限制条件的最短路
B. 题目链接:https://hihocoder.com/problemset/problem/1509 题意:给定一个长度为 n 的非负整数序列 a[1..n] 你需要求有多少个非负整数 S 满足以下两个条件: (1).0 ≤ S &amp;amp;amp;lt; 260 (2).对于所有 1 ≤ i &amp;amp;amp;lt; n ,有 (a[i] xor S) ≤ (a[i+1] xor S)思路:遍历每一对,找每一...原创 2018-07-18 17:41:48 · 374 阅读 · 0 评论 -
Bzoj1085 搜索+简单的A*估价函数
Bzoj1085思路:dfs搜索+A*的估价函数。需要注意的是终止条件需要减去1,因为*号也被统计在不同内。 Code:#include <bits/stdc++.h>using namespace std;const int AX = 5+6;char G[AX][AX];int f ; char target[AX][AX] = { {'1','1','...原创 2018-09-09 09:46:48 · 592 阅读 · 0 评论 -
Codeforces Round #484 (Div. 2) A 思维 B优先队列 C dfs
A#include <bits/stdc++.h>#define LL long longusing namespace std;int main(){ int n; string s; cin >> n ; cin >> s ; if( n == 1 ){ if( s[0] == '1' ) cout << "Yes" &...原创 2018-10-18 18:05:06 · 274 阅读 · 0 评论 -
51nod1416 两点
1416 两点题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注福克斯在玩一款手机解迷游戏,这个游戏叫做”两点”。基础级别的时候是在一个n×m单元上玩的。像这样: 每一个单元有包含一个有色点。我们将用不同的大写字母来表原创 2018-02-01 21:34:26 · 335 阅读 · 0 评论 -
Zoj1047 dfs联通
Image PerimetersTime Limit: 2 Seconds Memory Limit: 65536 KB Technicians in a pathology lab analyze digitized images of slides. Objects on a slide are selected for analysis by a mouse c原创 2018-01-09 11:23:36 · 254 阅读 · 0 评论 -
Zoj1008 dfs
Gnome TetravexTime Limit: 10 Seconds Memory Limit: 32768 KB Hart is engaged in playing an interesting game, Gnome Tetravex, these days. In the game, at the beginning, the player is give原创 2018-01-09 10:34:01 · 284 阅读 · 0 评论 -
POJ1182 食物链 带权并查集
动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。 有人用两种说法对这N个动物所构成的食物链关系进行描述: 第一种说法是"1 X Y",表示X和Y是同类。 第二种说法是"2 X Y",表示X吃Y。 此人对N个动物,用上述两种说法,一句接一句地原创 2017-08-02 19:02:18 · 471 阅读 · 0 评论 -
POJ1733 带权并查集+离散化
题意没看懂,半天都按着错的方向写。。意思是让你输出前面有几个对的,一旦有错,就立即输出答案!意思懂了之后还要知道这个是带权并查集比较经典的应用 [L,R] 转换成 ( L-1 , R] .将[L,R]这个区间化为(L-1,R],那么1的个数就可以表示为sum[R]-sum[L-1],也就确定了奇偶性如果L , R 的父节点相同,说明已经知道其奇偶性了,直接判断满足真话的关系即可,原创 2017-08-03 10:49:27 · 345 阅读 · 0 评论 -
POJ2492 带权并查集
A Bug's LifeTime Limit: 10000MS Memory Limit: 65536KTotal Submissions: 38437 Accepted: 12495DescriptionBackground Professor Hopper is researching the sexual behav原创 2017-08-03 19:19:21 · 346 阅读 · 0 评论 -
HDU1272 DFS 连通无环图的性质
https://vjudge.net/problem/HDU-12721.成环的时候,输入边的两个点有一个共同的父节点,那么这两个点就成环。2.连通的时候,根节点数为1。也可以根据 Vertex = edgenum + 1 来做(顶点数 = 边数 + 1) 并且仍然不能成环#include using namespace std;const int AX = 1e5+6原创 2017-08-04 16:00:48 · 540 阅读 · 0 评论 -
Codeforces Round #428 (Div. 2) A B C
A. Arya and Brantime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBran and his older sister Arya are from the same hous原创 2017-08-18 22:14:09 · 353 阅读 · 0 评论 -
51nod 1489 蜥蜴和地下室
1489 蜥蜴和地下室题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注哈利喜欢玩角色扮演的电脑游戏《蜥蜴和地下室》。此时,他正在扮演一个魔术师。在最后一关,他必须和一排的弓箭手战斗。他唯一能消灭他们的办法是一个火球咒语。如果哈利用他的火球咒语攻击第i个弓箭手(他们从左到右原创 2017-09-30 12:46:16 · 437 阅读 · 0 评论 -
例题 6 - 17 Undraw the Trees UVA - 10562
原题连接:https://vjudge.net/problem/UVA-10562题意:根据给出的树画出树的结构思路:输入树之后,找哪个有根,然后深度搜索。Code:#include using namespace std;const int AX = 1e2 + 66 ;string buf[AX];int cnt ;void dfs(int r , int c ){原创 2017-10-22 09:02:14 · 379 阅读 · 0 评论 -
例题6-12 UVA572 Oil Deposits 基础dfs求连通块
题目连接:https://vjudge.net/problem/UVA-572思路:基础dfsCode:(紫书版本)#include #include #include using namespace std;const int AX = 1e2+5;char mp[AX][AX];int id[AX][AX];int n , m;void dfs( int r , i原创 2017-10-14 10:42:00 · 353 阅读 · 0 评论 -
例题6-13Ancient Messages UVA1103 dfs求连通块+16进制转2进制
题目链接:https://vjudge.net/problem/UVA-1103题意:给出几种象形符号,然后给出16进制的像素描述,让你根据描述字典序输出描述中的象形符号。思路:几种象形符号可以转化成不同的连通块个数。先转换16进制为2进制,然后给图形外面加一层“边框”0,第一次dfs遍历将外面多余的0全部变成 ‘ - ’ ,然后再进行dfs遇到‘1’就找它是否包围0,包围了几个就对应相应原创 2017-10-15 10:32:32 · 353 阅读 · 0 评论 -
例题6-8 二叉树的递归遍历 uva548
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=489思路:根据输入的后序遍历(最后的那个数)找到树根,然后再在给出的中序遍历中找到树根,这样就能根据后序中序遍历的数据递归构造左右子树,最后dfs求出最优解Code:#include原创 2017-10-08 16:46:37 · 452 阅读 · 0 评论 -
A. Nephren gives a riddle dfs
A. Nephren gives a riddletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhat are you doing at the end of the worl原创 2017-12-10 15:44:53 · 349 阅读 · 0 评论 -
zoj 1191
The Die Is CastTime Limit: 2 Seconds Memory Limit: 65536 KB InterGames is a high-tech startup company that specializes in developing technology that allows users to play games over the原创 2018-01-11 16:48:58 · 344 阅读 · 0 评论 -
zoj 1191 The Die Is Cast dfs
The Die Is CastTime Limit: 2 Seconds Memory Limit: 65536 KB InterGames is a high-tech startup company that specializes in developing technology that allows users to play games over the原创 2018-01-12 15:29:32 · 305 阅读 · 0 评论 -
Zoj 2100 dfs遍历
SeedingTime Limit: 2 Seconds Memory Limit: 65536 KB It is spring time and farmers have to plant seeds in the field. Tom has a nice field, which is a rectangle with n * m squares. There原创 2018-01-12 15:30:36 · 252 阅读 · 0 评论 -
HDU 3038 带权并查集
可以清晰看出val - dist[y] + dist[x] 就是yy到祖先的距离dist[yy]#include #include #include using namespace std;const int AX = 2e5+666;const int MAXN = 4e4+666;int pre[AX];int dist[AX];int ans ;int n,m;原创 2017-08-02 16:04:50 · 273 阅读 · 0 评论