
数据结构
♡-流浪孩
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Educational Codeforces Round 98 (Rated for Div. 2)------Radio Towers
题目There are n+2 towns located on a coordinate line, numbered from 0 to n+1. The i-th town is located at the point i.You build a radio tower in each of the towns 1,2,…,n with probability 12 (these events are independent). After that, you want to set the s原创 2020-11-21 10:24:44 · 168 阅读 · 0 评论 -
牛客小白月赛29(签到:A、E、G、H)
A贪心,由于基地可以重复销毁,所以找出找出每架战机可轰炸基地的最大价值,排序之后贪心找一下即可#include<iostream>#include<algorithm>using namespace std;const int N = 1e6 + 15;struct node{ int d, v;}no[N];bool cmp(node a, node b){ if(a.d == b.d) return a.v < b.v;原创 2020-11-15 08:31:29 · 218 阅读 · 0 评论 -
Codeforces Round #672 (Div. 2)------Cubes Sorting
题目Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs n cubes. i-th cube has a volume ai.Wheatley has to place cubes in such a way that they原创 2020-11-10 14:34:29 · 129 阅读 · 0 评论 -
Codeforces Round #678 (Div. 2)------Binary Search
题目Andrey thinks he is truly a successful developer, but in reality he didn’t know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number x in an array.原创 2020-10-31 10:25:00 · 256 阅读 · 0 评论 -
2020牛客国庆集训派对day2(A,C,D,E,F,G,H,J,)
A、AKU NEGARAKU约瑟夫环裸题AC代码#include<iostream>#include<stdio.h>using namespace std;#define ll long longll yuesefu(ll n, ll m) { if (n == 1) { return 0; } else { return (yuesefu(n - 1, m) + m) % n; }}int mai原创 2020-10-03 10:04:24 · 346 阅读 · 0 评论 -
2020牛客国庆集训派对day1 ------ ABB(马拉车裸题 + 条件判断)
题目Fernando was hired by the University of Waterloo to finish a development project the university started some time ago. Outside the campus, the university wanted to build its representative bungalow street for important foreign visitors and collaborators原创 2020-10-03 09:42:00 · 799 阅读 · 0 评论 -
蓝桥杯算法训练 ------ Two k-Convex Polygons
题目给定n个棍子的长度和整数k,求能否在其中选出2k个棍子拼成两个凸多边形。使得两个凸多边形都恰好有k跟棍子组成,且任意相邻的边都不共线。输入第一行包括两个正整数n,k,表示棍子总数和多边形边数。第二行包括n个正整数,表示每根棍子的长度。输出第一行输出一个单词Yes或者No表示是否能选出满足要求的2k个棍子。如果第一行输出的是Yes,则第二行要输出方案。输入的棍子从1开始按照输入顺序编号,你需要输出2k个空格隔开的正整数,前k个表示组成第一个凸多边形的棍子的编号,后k个表示组成第二个凸多边形棍原创 2020-10-02 10:48:02 · 742 阅读 · 1 评论 -
2019 CCPC 秦皇岛 Gym - 102361F(HDU - 6736 ) ------ Forest Program
题目The kingdom of Z is fighting against desertification these years since there are plenty of deserts in its wide and huge territory. The deserts are too arid to have rainfall or human habitation, and the only creatures that can live inside the deserts are原创 2020-09-26 19:18:56 · 218 阅读 · 0 评论 -
冒险家(八数码问题)
这题是翻译了八数码问题(POJ — 2893),然后稍加修改。Description小D在地下世界探索时,找到了一座藏有无数奇珍异宝的王国,可是进入王国有一扇门,当且仅当你将门上的矩阵变成国王心中的完美矩阵时,大门方可打开。一向不喜欢数字的小D傻眼了,现求助于你,请你帮助他看他是否能进入王国,获得奇珍异宝。规则如下:给定一个MN的矩阵(M和N其中必有一个奇数),矩阵上滑贴的编号为1 – (...原创 2020-02-23 12:10:02 · 666 阅读 · 0 评论 -
网络流之二分图匹配(POJ-1274 The Perfect Stall)
DescriptionFarmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering problems, all the stalls in the new barn are different...原创 2020-02-05 14:03:38 · 230 阅读 · 0 评论 -
网络流之最小费用流(POJ-2135 Farm Tour)
DescriptionWhen FJ’s friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1…N, the first of which contains his house and the Nth of...原创 2020-02-05 13:55:13 · 184 阅读 · 0 评论 -
POJ-3281(Dining)
DescriptionCows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others.Farmer John has cooked fabulous meals for his cows, but he forgot to c...原创 2020-02-05 13:45:14 · 173 阅读 · 0 评论 -
回顾(单调栈) poj --- 2559
栈的运用(单调栈)单调栈是一种特殊的栈,特殊之处在于栈内的元素都保持一个单调性,可能为单调递增,也可能为单调递减。模拟一个单调递增的单调栈4 5 ...原创 2020-01-22 00:29:13 · 232 阅读 · 0 评论 -
字典树---最大异或对(AcWing 143)
在给定的N个整数A1,A2……AN中选出两个进行xor(异或)运算,得到的结果最大是多少?输入格式第一行输入一个整数N。第二行输入N个整数A1~AN。输出格式输出一个整数表示答案。数据范围1≤N≤105,0≤Ai<231输入样例:31 2 3输出样例:3思路:将所有的数看成二进制,建一棵字典树,查询所有数在字典树中每个二进制位时尽量往相反位置走的结果,不断更新...原创 2020-01-19 14:53:59 · 178 阅读 · 0 评论 -
贪心背后的故事Codeforces 995B(Suit and Tie)
题目:Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Alle...原创 2020-01-18 23:33:49 · 309 阅读 · 0 评论 -
Codeforces 1013D(Chemical table)
题意:给定你一个n * m的矩阵,这里面已知标记了t个点,对于任意的两行两列,如果交汇的四个格子中有3个被标记且第四个未被标记,那么第四个点将会自动打上标记,现在请问,你还需要手动标记几个点,可以使矩阵内的所有点都被标记。思路:挺好的一个并查集的思维题,将所有的点看成一个集合,将横坐标和纵坐标相关联,最后看这个集合里有多少个非关联的点,那么减一就是答案。#include<iostre...原创 2020-01-18 18:27:30 · 222 阅读 · 0 评论 -
Codeforces 1263D(Secret Passwords )
题目:One unknown hacker wants to get the admin’s password of AtForces testing system, to get problems from the next contest. To achieve that, he sneaked into the administrator’s office and stole a piec...原创 2020-01-14 15:40:59 · 243 阅读 · 0 评论 -
Codeforces 1106D(Lunar New Year and a Wander )
题目:Lunar New Year is approaching, and Bob decides to take a wander in a nearby park.The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at the n...原创 2020-01-13 00:26:32 · 248 阅读 · 0 评论 -
练习搜索之三维迷宫(HDU-2102)
A计划题目:可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示...原创 2020-01-11 23:27:40 · 181 阅读 · 0 评论 -
POJ-1456(并查集)
回顾并查集。题意:给定N个商品,每个商品有利润pi和过期时间di,每天只能卖一个商品,过期商品不能在卖,求如何安排每天卖的商品,可以使收益最大。(1 <= N, pi, di <= 10000)样例:4 50 2 10 1 20 2 30 17 20 1 2 1 10 3 100 2 8 2 5 20 50 10思路:把商品按照利润从大...原创 2020-01-11 14:59:13 · 173 阅读 · 0 评论 -
区间第K大(POJ-2104)
可持久化线段树不是一颗完全二叉树,所以不能用层次序编号,而应该直接记录每个节点的左、右子节点的编号。可持久化线段树维护了每次操作后线段树的历史形态。下面举个简单的例子来理解一下:以poj-2104为例;这棵树是一颗不用修改的线段树题意:即多次查询,查询区间第K大的数。POJ-2104 (区间第k大)//主席树的学习--区间第k大//区间第k大又可以用整体分治算法,归并树,线段树套平衡树...原创 2020-01-10 16:35:24 · 221 阅读 · 0 评论 -
POJ-1258 最小生成树(Prim)
最小生成树一个有n个节点的连通图的生成树是原图的极小连通子图,且包含原图中的所有n个结点,并且有保持图连通的最少的边。最小生成树可以用Kruskal算法或者prim算法求出。kruskal 算法的过程为不断对子图进行合并,直到形成最终的最小生成树。prim 算法的过程则是只存在一个子图,不断选择顶点加入到该子图中,即通过对子图进行扩张,直到形成最终的最小生成树。https://www.ji...原创 2019-12-26 14:42:13 · 235 阅读 · 0 评论 -
归并排序
归并排序归并排序是建立在归并操作上的一种有效的排序算法,是采用分治法的一个典型应用。其时间复杂度为O(n log n)归并排序的步骤如下:划分求解:将序列分成元素个数尽量相等的两半。递归求解:将两半元素分别排序。合并问题:将两个有序表合并在一起当我们要排序一个数组的时候,归并排序法首先将这个数字分成一半,然后给左边的数组排序,右边的数组给排序,之后将它们归并起来,而我们在对左边和右边...原创 2019-12-25 16:40:42 · 180 阅读 · 0 评论 -
线段树(区间求和,区间加,单点更新等)
线段树线段树是一种二叉搜索树。它将一段区间划分为若干个单位区间,每一个节点都储存着一个区间。线段树可做 区间求和,区间最值,区间更新,单点更新等操作以区间和为例来做介绍:建树const int maxn=1000000+5;struct Tree{ int l,r; int val; int lazy,tag;//标记,需要区间更新时使用}tree[maxn...原创 2019-12-23 19:13:22 · 497 阅读 · 0 评论 -
Next 数组及KMP(hdu-1358)
Next 数组及KMPKMP算法的核心是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的。具体实现就是通过一个getnext()函数实现,函数本身包含了模式串的局部匹配信息。KMP算法的时间复杂度O(m+n)。其中最难理解的部分即next数组的求法以及回溯前缀数组**前缀数组中存储的是这个字符串前缀和后缀中相同子串的最长长度 **next 数组考虑的是除当前字符外的...原创 2019-12-22 20:23:51 · 189 阅读 · 0 评论 -
POJ-3690 二维哈希
二维哈希题意:给定一个由和0组成的大小为nm的匹配对象,和T个大小为pq的匹配模式,求匹配对象中至少出现一次匹配模式的个数思路:将每一行看成一个字符串,计算从每个位置开始长度为Q的字符串子串的哈希值,然后把得到的哈希值在列方向看成一个字符串,计算每个位置开始长度为P的字符串子串的哈希值,通过上述步骤,可以得到这个nm的匹配对象的所有的pq的子阵的哈希值*注意:两次哈希值的计算选用不同的基数...原创 2019-12-21 16:08:02 · 156 阅读 · 0 评论