摘要: 加载本页面时,公式可能未渲染(显示乱码)请刷新该页面重试 问题:给出两串字符 $text[]="adsgwadsxdsgwadsgz"$长度为N $pattern[]="dsgwadsgz"$长度为M 查找pattern字符串是否在text出现过并输出所在位置。 一、Brute Force朴素匹配算 阅读全文
posted @ 2019-10-29 16:44 cafu-chino 阅读(779) 评论(0) 推荐(1) 编辑
摘要: 知识点 这是一个比较零碎的小点,之前并不知道,只会暴力233333 一个数组$a$(假设数组长为$a$),然后数组$a$的下标在$[l,r]$范围内元素加上/减去一个数$x$,可以这样操作: $a[l]=a[l]+n;a[r+1]=a[r+1] n$ 求操作后的$a[k]$即为: $a[k]=\su 阅读全文
posted @ 2019-10-29 16:34 cafu-chino 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 并查集实质是一个树状结构,即给出节点之间的关系并存入数据之中,并能够随时查找两节点之间的关系 有关并查集的概念 父节点: 数据库管理中的数据模型中,早期阶段的层次模型和网状模型中,一个属性如果有上一级,则称这个上一级是它的父结点,如果没有上一级,则这个属性则无父结点。 **根节点:**即没有父节点的 阅读全文
posted @ 2019-10-29 16:31 cafu-chino 阅读(196) 评论(0) 推荐(0) 编辑
摘要: "原题链接(戳我~)" 题目大意&解题思路 有n个节点,然后执行I_u_v(把u的父节点设为v)和E_u(询问u到根节点的距离)。 利用带权并查集 Sample Input Sample output 代码样例 利用pair存放父节点(first)以及权值(second) 计算距离 查找根节点(fi 阅读全文
posted @ 2019-10-29 16:25 cafu-chino 阅读(129) 评论(0) 推荐(0) 编辑
摘要: "题目链接(戳我)" 题目大意 有n个人被分为m组,现在给第i个人传递一个消息,这个人算在的组成员都能够接收到消息并按此方法专递下去知道不能够喘息为止,请依次打印出以第i个人为消息开始到结束后能够接收到消息的人数; 解题思路 利用并查集,把处在相同组的人放在同一个集合中,第i个人所在集合的人数即为最 阅读全文
posted @ 2019-10-29 16:23 cafu-chino 阅读(122) 评论(0) 推荐(0) 编辑
摘要: There is an array with n elements a 1, a 2, ..., a n and the number x . In one operation you can select some i (1 ≤ i ≤ n ) and replace element a i wi 阅读全文
posted @ 2019-10-29 16:22 cafu-chino 阅读(117) 评论(0) 推荐(0) 编辑
摘要: Description You are given a system of pipes. It consists of two rows, each row consists of $n$ pipes. The top left pipe has the coordinates $(1,1)$ an 阅读全文
posted @ 2019-10-29 16:20 cafu-chino 阅读(345) 评论(0) 推荐(0) 编辑
摘要: Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spanning Tree): Consider a connected, undirected graph 阅读全文
posted @ 2019-10-29 16:19 cafu-chino 阅读(119) 评论(0) 推荐(0) 编辑
摘要: Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20725 Accepted: 9192 Description A supermarket has a set Prod of products on sale. It earns 阅读全文
posted @ 2019-10-29 16:17 cafu-chino 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 1、朴素判断素数 这种方法就是将给出的数判断能否找到处1以及它本身以外的因数。 代码样例 #include <bits/stdc++.h> using namespace std; bool f(int n){ for(int i=2; i*i <= n; i++){ if(n%i == 0) re 阅读全文
posted @ 2019-10-29 16:15 cafu-chino 阅读(326) 评论(0) 推荐(0) 编辑