
基础算法
文章平均质量分 82
CNG Steve·Curcy
death is what gives life meaning, to know your days are numbered,your time is short.
展开
-
第十届蓝桥杯C/C++ B组 E 迷宫
E题 迷宫[问题描述]:下图给出了一个迷宫的平面图,其中标记为 1 的为障碍,标记为 0 的为可 以通行的地方。010000000100001001110000 迷宫的入口为左上角,出口为右下角,在迷宫中,只能从一个位置走到这 个它的上、下、左、右四个方向之一。 对于上面的迷宫,从入口开始,可以按DRRURRDDDR 的顺序通过迷宫, 一共 10 步。其中 D、U、L、R 分别表示向...原创 2020-03-26 22:13:48 · 352 阅读 · 0 评论 -
二分(折半)笔记
文章目录二分(折半)查找统计一个大范围中具有某些特性的数据二分(折半)查找菜鸡今天又开始了一个新的算法,废话不多说,开始笔记。二分查找是一个十分常用的算法,适用于对带有单调性的数据进行处理或查找。大多数题目可能没那么显示,需要自己来找这个单调性在哪,所以这就是一个重点,具体的用法和代码很简单,就那么几行,但是对于折半的条件却需要有严格的要求。统计一个大范围中具有某些特性的数据[牛客]完全平...原创 2020-01-21 13:08:18 · 430 阅读 · 0 评论 -
最长回文 HDU - 3068( manacher )
给出一个只由小写英文字符a,b,c…y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba, abba等Input输入有多组case,不超过120组,每组输入为一行小写英文字符a,b,c…y,z组成的字符串S两组case之间由空行隔开(该空行不用处理)字符串长度len <= 110000Output每一行一个整数x,对应一组case,表示该组ca...原创 2019-02-21 09:55:21 · 107 阅读 · 0 评论 -
CSL 的魔法(牛客竞赛)
题目链接参考代码题目思路:这个题目明显就是要排序的,第一个序列最小值和第二个序列最大值相对应,以此类推。(但是只知道应该是这样,但代码实现……还得看大佬代码)只能说自己还是太菜了,读大佬的代码还读了一会,然后做了下注释,做下笔记。#include <cstdio>#include <cstring>#include <iostream>#in...原创 2019-04-01 20:10:13 · 239 阅读 · 0 评论 -
CSL的字符串(牛客竞赛)
题目链接参考代码(其实本来最早见到这个思想不是这位大佬的,但是由于牛客提交太多了,我参考的那个代码找不到了)解释都放在代码里面了,做了些笔记。#include<bits/stdc++.h>using namespace std;typedef long long LL;const int inf = 0x3f3f3f3f;int cnt[505];bool vis[5...原创 2019-04-01 20:20:28 · 242 阅读 · 0 评论 -
CodeForces - 260 - BAncient Prophesy(暴力)
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters “-”.We’ll say that some date is mentioned in t...原创 2018-11-13 09:34:11 · 211 阅读 · 0 评论 -
HDU - 1172 - 猜数字(枚举)
HDU - 1172 - 猜数字猜数字游戏是gameboy最喜欢的游戏之一。游戏的规则是这样的:计算机随机产生一个四位数,然后玩家猜这个四位数是什么。每猜一个数,计算机都会告诉玩家猜对几个数字,其中有几个数字在正确的位置上。 比如计算机随机产生的数字为1122。如果玩家猜1234,因为1,2这两个数字同时存在于这两个数中,而且1在这两个数中的位置是相同的,所以计算机会告诉玩家猜对了2个数字...原创 2018-08-19 11:32:37 · 593 阅读 · 0 评论 -
HDU - 2089 - 不要62(暴力枚举)
HDU - 2089 - 不要62杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。 不吉利的数字为所有含有4或62的号码。例如: 62315 73418 88914 都属于不吉利号码。但是,61152虽然含有...原创 2018-08-18 21:29:33 · 583 阅读 · 0 评论 -
HDU - 6182 - A Math Problem (枚举 & 打表)
HDU - 6182 - A Math ProblemYou are given a positive integer n, please count how many positive integers k satisfy kk≤nkk≤n. Input There are no more than 50 test cases. Each case only contains a ...原创 2018-08-10 21:11:22 · 295 阅读 · 0 评论 -
HDU - 1022 - Train Problem I(栈的应用)
As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over t...原创 2018-08-23 23:50:47 · 198 阅读 · 0 评论 -
CodeForces - 853A - Planning(C++ 优先队列)
CodeForces - 853A - PlanningHelen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart...原创 2018-08-23 23:02:40 · 373 阅读 · 0 评论 -
vector C++(一)
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sangyongjia/article/details/51122965 &nb...转载 2018-08-23 08:40:14 · 157 阅读 · 0 评论 -
std::endl与'\n'的区别(c++基础)
“\n” 表示内容为一个回车符的字符串。std::endl 是流操作子,输出的作用和输出 “\n” 类似,但可能略有区别。std::endl 输出一个换行符,并立即刷新缓冲区。例如:std::cout &amp;lt;&amp;lt; std::endl;相当于: std::cout &amp;lt;&amp;lt; '\n' &amp;lt;&amp;lt; std::flush;原创 2018-09-30 22:31:09 · 9597 阅读 · 1 评论 -
归并排序
归并排序是所有排序算法中最快的算法了吧,O(nlogn)的时间复杂度,只需要一个辅助数组,就能实现排序;基本思想是分治,这种模式也被引入了CDQ分治。(不知道这么说对不对,因为要学习CDQ才记录一下这个排序)首先我们将整个数据分成两个部分,进行子区间内部排序,当然实现方式与大区间的实现方式一样:分为子区间,直至不能再分。这样,我们就可以保证,我们递归处理完两个子区间的问题之后,两个子区间内部都已...原创 2019-04-15 22:00:51 · 121 阅读 · 0 评论 -
deepin(linux)vscode的tasks.json和launch.json配置文件
参考文章tasks是用在launch前执行的任务,launch是读取执行文件。在当前文件是C++的情况下,tasks可以被用来做编译,而launch用来执行编译好的文件。task.json:// tasks.json{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentatio...原创 2019-08-15 16:33:45 · 1830 阅读 · 0 评论 -
HDU - 5491 The Next(思维&二进制)
Let L denote the number of 1s in integer D’s binary representation. Given two integers S1 and S2, we call D a WYH number if S1≤L≤S2.With a given D, we would like to find the next WYH number Y, which...原创 2019-09-10 09:32:34 · 163 阅读 · 0 评论 -
DNA Alignment CodeForces - 520C(思维)
Vasya became interested in bioinformatics. He’s going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.Let’s assu...原创 2018-12-26 11:20:27 · 273 阅读 · 0 评论 -
CodeForces - 520B Two Buttons(逆向思维)
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies th...原创 2018-12-28 14:36:28 · 184 阅读 · 0 评论 -
Gym 101911A Coffee Break(优先队列)
Recently Monocarp got a job. His working day lasts exactly m minutes. During work, Monocarp wants to drink coffee at certain moments: there are n minutes a1,a2,…,an, when he is able and willing to ta...原创 2018-12-17 18:19:17 · 383 阅读 · 0 评论 -
51Nod - 1279 - 扔盘子(思维题)
51Nod - 1279 - 扔盘子有一口井,井的高度为N,每隔1个单位它的宽度有变化。现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,则圆盘被卡住(恰好等于的话会下去)。 盘子有几种命运:1、掉到井底。2、被卡住。3、落到别的盘子上方。 盘子的高度也是单位高度。给定井的宽度和每个盘子的宽度,求最终落到井内的盘子数量。如图井和盘子信息如下: 井:5 6 4 3 6 ...原创 2018-08-10 20:31:31 · 555 阅读 · 0 评论 -
CodeForces - 949A - Zebras(思维)
CodeForces - 949A - ZebrasOleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad d...原创 2018-08-12 08:31:19 · 256 阅读 · 0 评论 -
CodeForces - 632C - The Smallest String Concatenation(思维)
CodeForces - 632C - The Smallest String ConcatenationYou’re given a list of n strings a1, a2, …, an. You’d like to concatenate them together in some order such that the resulting string would be lex...原创 2018-08-18 21:43:08 · 259 阅读 · 0 评论 -
HDU - 5912 - Fraction (模拟)
题目链接 Mr. Frog recently studied how to add two fractions up, and he came up with an evil idea to trouble you by asking you to calculate the result of the formula below: As a talent, can you figur...原创 2018-09-07 08:55:40 · 296 阅读 · 0 评论 -
nefu115 - 斐波那契的整除(思维 & 数论)
题目链接Time Limit:1000ms Memory Limit:65536KDescription已知斐波那契数列有如下递归定义,f(1)=1,f(2)=1, 且n>=3,f(n)=f(n-1)+f(n-2),它的前几项可以表示为1, 1,2 ,3 ,5 ,8,13,21,34…,现在的问题是想知道f(n)的值是否能被3和4整除,你知道吗?Input输入数据有若干组,每组数据...原创 2018-09-17 20:48:32 · 688 阅读 · 0 评论 -
HDU - 5916 - Harmonic Value Description (思维 & 构造)
题目链接 The harmonic value of the permutation p1,p2,⋯pnp1,p2,⋯pn is n-1 ∑ gcd(pi.pi+1) i= 1Mr. Frog is wondering about the permutation whose harmonic value is the strictly k-th smallest among a...原创 2018-09-07 14:48:32 · 161 阅读 · 0 评论 -
CodeForces - 608C - Chain Reaction (dp & 二分)
题目链接 There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (di...原创 2018-09-11 10:57:01 · 223 阅读 · 0 评论 -
分石子(思维题 & 二进制)
Description有n个石子,将它分成k堆,对于[1,n]的任意一个数,都能用某几堆石子组成(每一堆只能用一次),求k的最小值。Input多组样例输入输出,输入n(1=&lt;n&lt;=1e18)Output每个测试样例输出k,占一行,k的含义如题目所述Sample Input 1621Sample Output 1321Hint分成的任意两个石子堆中石子个数可...原创 2018-09-22 11:23:02 · 976 阅读 · 0 评论 -
CodeForces - 337B - Routine Problem(比例问题 & 思维)
Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie’s frame has horizontal to vertical length ratio c:d. Manao adjus...原创 2018-10-08 08:45:32 · 422 阅读 · 0 评论 -
Codeforces 134C - Swaps(优先队列)
There are n players sitting at a round table. All of them have s cards of n colors in total. Besides, initially the first person had cards of only the first color, the second one had cards of only the...原创 2018-10-15 15:54:58 · 260 阅读 · 0 评论 -
51NOD 1272 - 最大距离(思维)
给出一个长度为N的整数数组A,对于每一个数组元素,如果他后面存在大于等于该元素的数,则这两个数可以组成一对。每个元素和自己也可以组成一对。例如:{5, 3, 6, 3, 4, 2},可以组成11对,如下(数字为下标):(0,0), (0, 2), (1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (3, 3), (3, 4), (4, 4), (5, 5)。其中(1...原创 2018-10-16 11:23:22 · 270 阅读 · 1 评论 -
HDU - 4545 - 魔法串(思维)
小明和他的好朋友小西在玩一个新的游戏,由小西给出一个由小写字母构成的字符串,小明给出另一个比小西更长的字符串,也由小写字母组成,如果能通过魔法转换使小明的串和小西的变成同一个,那么他们两个人都会很开心。这里魔法指的是小明的串可以任意删掉某个字符,或者把某些字符对照字符变化表变化。如: 小西的串是 abba; 小明的串是 addba; 字符变化表 d b (表示d能转换成b)...原创 2018-10-17 09:15:17 · 225 阅读 · 0 评论 -
CodeForces - 195B - After Training
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The ...原创 2018-10-20 09:37:23 · 211 阅读 · 0 评论 -
CodeForces - 260A - Adding Digits(思维)
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.One operation of lengthening a number means adding ex...原创 2018-11-13 09:27:23 · 276 阅读 · 0 评论 -
CodeForces - 264A - Escape from Stones(栈和队列的应用)
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will esc...原创 2018-11-14 10:51:48 · 255 阅读 · 0 评论 -
CodeForces - 298D Fish Weight(思维)
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type...原创 2018-11-28 13:12:18 · 205 阅读 · 0 评论