自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

李狗嗨acc

Time accumulates

  • 博客(82)
  • 收藏
  • 关注

原创 线性表的顺序表示

#include <iostream>#include <cstdlib>#include <cstring>#define MaxSize 50using namespace std;typedef struct{ //静态分配 int length; int data[MaxSize];}SqList;typedef ...

2019-07-05 09:09:01 264

原创 [蓝桥杯][2013年第四届真题]危险系数(tarjan求割点)

构造一颗以u为根的树,然后一、求所有割点二、对待每个可能的割点,要保证u和v都位于这个割点的两端#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <cmath>#include <algorith...

2019-05-23 20:25:19 251

原创 [蓝桥杯][2013年第四届真题]剪格子

一定要好好审题啊!!!行号和列号跟题意要求的搞反了,结果de到怀疑人生了。。。这个题给的数据量不大,所以我就放心大胆的在每个中间节点里各开了一个vis标记数组,用来记录每一条广搜路径走过的节点。#include <iostream>#include <cstring>#include <cstdlib>#include <vector...

2019-05-22 22:24:43 290

原创 [蓝桥杯][2014年第五届真题]兰顿蚂蚁

#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <cmath>#include <algorithm>#include <set>#include <queue>#incl...

2019-05-22 16:52:04 175

原创 [蓝桥杯][2013年第四届真题]买不到的数目

扩展欧几里得互质的两个数a和b,不能用ax+by(x、y为非负整数)的形式表示出的最大整数是a*b-a-ba和b不互质的情况下,ax+by = k*gcd(a,b),其中gcd(a,b)>1。那么在k无限大的情况下,不能表示的数就有无限多个,没有最大整数的存在。互质时,原文a或者b是1的情况下容易证明.以下情况都是a>1且b>1的情况.首先证明ab-a-b不...

2019-05-22 16:25:23 161

原创 [蓝桥杯][历届试题]九宫重排

BFS+查重因为通过不同的路径到达同一个点会产生不同的串,不具有唯一性,所以查重不再是查找一个点到没到过,而是找一个中间串出没出现过,set一下就行了#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <cmat...

2019-05-22 10:50:21 165

原创 [蓝桥杯][2013年第四届真题]打印十字图

https://www.dotcpp.com/oj/problem1442.html这种题对代码细节观察和处理还是很有帮助的,而且题目难度一般不大,可以拿来练手。图形对称,规律好找的情况下先完成部分再拷贝,我的做法是先完成下半部分。观察规律,除了中间一个十字比较特殊外,其余的都是大小比例不同的十字而已。在这里定义四个变量,left:十字最左端边界right:十字最右端边界...

2019-05-18 22:20:19 298

原创 Currency Exchange(寻找正权环)

寻找正权环就是常规Bellman算法的反向操作,将松弛更小值改为松弛更大值。#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <cmath>#include <algorithm>#include ...

2019-05-17 17:43:25 274

转载 BellmanFord

原文链接Bellman-Ford算法的优点是可以发现负圈,缺点是时间复杂度比Dijkstra算法高。而SPFA算法是使用队列优化的Bellman-Ford版本,其在时间复杂度和编程难度上都比其他算法有优势。算法流程(1)初始化:将除起点s外所有顶点的距离数组置无穷大 d[v] = INF, d[s] = 0(2)迭代:遍历图中的每条边,对边的两个顶点分别进行一次松弛操作,直到没有...

2019-05-17 17:38:05 314

原创 Caocao's Bridges(Tarjan求最小割边,去重边)

去重边:对于无向图而言,网上主要两种写法,第一种给每一条边的正反方向都分配一个相同但唯一的id,那么在判断时如果两条边的id是一样的,就说明是一条边,这条边就不要走了。在tarjan算法中,对于这种写法,传入参数就要有两个(出发点u,到达u的边的id)void Tarjan(int u,int id){ //当前点u,来到u的边的id low[u] = dfn[u...

2019-05-17 11:51:57 404

原创 强连通分量Tarjan算法

Tarjan算法#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <cmath>#include <algorithm>#include <set>#include <queu...

2019-05-15 20:59:43 150

转载 高级树状数组

博客地址1. 单点修改 + 区间查询最简单的树状数组就是这样的:void add(int p, int x){ //给位置p增加x while(p <= n) sum[p] += x, p += p & -p;}int ask(int p){ //求位置p的前缀和 int res = 0; while(p) res += sum[p], ...

2019-05-14 21:55:51 130

转载 SPFA

转载适用范围:给定的图存在负权边,这时类似Dijkstra等算法便没有了用武之地,而Bellman-Ford算法的复杂度又过高,SPFA算法便派上用场了。 我们约定有向加权图G不存在负权回路,即最短路径一定存在。当然,我们可以在执行该算法前做一次拓扑排序,以判断是否存在负权回路,但这不是我们讨论的重点。算法思想:我们用数组d记录每个结点的最短路径估计值,用邻接表来存储图G。我们采取的方法是...

2019-05-13 20:52:21 143

原创 Mishka and Interesting sum(树状数组前缀和)

Little Mishka enjoys programming. Since her birthday has just passed, her friends decided to present her with array of non-negative integersa1, a2, ..., anofnelements!Mishka loved the array and ...

2019-05-13 18:50:53 976

原创 Ultra-QuickSort(树状数组求逆序对)

In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted ...

2019-05-12 19:23:41 176

转载 树状数组

树状数组入门求逆序对(原理,感觉理解最顺畅的一篇了)树状数组求逆序对(+离散化)

2019-05-12 19:18:10 96

原创 Ignatius and the Princess IV@HDU1029

"OK, you are not too bad, em... But you can never pass the next test." feng5166 says."I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to t...

2019-03-23 21:57:01 100

原创 Nightmare Ⅱ@HDU3085

Last night, little erriyue had a horrible nightmare. He dreamed that he and his girl friend were trapped in a big maze separately. More terribly, there are two ghosts in the maze. They will kill the ...

2019-03-23 21:39:34 131

原创 堆排序

堆排序思路#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <cmath>#include <algorithm>#include <set>#include <queue&gt...

2019-03-23 19:36:30 185

原创 螺旋折线

如图p1.png所示的螺旋折线经过平面上所有整点恰好一次。 对于整点(X, Y),我们定义它到原点的距离dis(X, Y)是从原点到(X, Y)的螺旋折线段的长度。 例如dis(0, 1)=3, dis(-2, -1)=9 给出整点坐标(X, Y),你能计算出dis(X, Y)吗?【输入格式】X和Y 对于40%的数据,-1000 <= X, Y <= 1...

2019-03-21 19:36:03 246

原创 乘积最大

给定N个整数A1, A2, ... AN。请你从中选出K个数,使其乘积最大。请你求出最大的乘积,由于乘积可能超出整型范围,你只需输出乘积除以1000000009的余数。注意,如果X<0, 我们定义X除以1000000009的余数是负(-X)除以1000000009的余数。即:0-((0-x) % 1000000009)【输入格式】第一行包含两个整数N和K。以下N行每行一...

2019-03-20 21:07:22 161

原创 日志统计

尺取#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <cmath>#include <algorithm>#include <set>#include <queue>#...

2019-03-20 16:11:52 91

原创 测试次数@蓝桥

标题:测试次数x星球的居民脾气不太好,但好在他们生气的时候唯一的异常举动是:摔手机。各大厂商也就纷纷推出各种耐摔型手机。x星球的质监局规定了手机必须经过耐摔测试,并且评定出一个耐摔指数来,之后才允许上市流通。x星球有很多高耸入云的高塔,刚好可以用来做耐摔测试。塔的每一层高度都是一样的,与地球上稍有不同的是,他们的第一层不是地面,而是相当于我们的2楼。如果手机从第7层扔下去没摔坏,但...

2019-03-20 11:04:22 109

原创 明码

#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <cmath>#include <algorithm>#include <set>#include <queue>#incl...

2019-03-19 18:16:53 178

原创 本原串@HDU2197

由0和1组成的串中,不能表示为由几个相同的较小的串连接成的串,称为本原串,有多少个长为n(n&lt;=100000000)的本原串?答案mod2008.例如,100100不是本原串,因为他是由两个100组成,而1101是本原串。Input输入包括多个数据,每个数据一行,包括一个整数n,代表串的长度。Output对于每个测试数据,输出一行,代表有多少个符合要求本原串,答案...

2019-03-18 11:16:11 169

转载 LCS

出处0、前言程序员编程艺术系列重新开始创作了(前十章,请参考程序员编程艺术第一~十章集锦与总结)。回顾之前的前十章,有些代码是值得商榷的,因当时的代码只顾阐述算法的原理或思想,所以,很多的与代码规范相关的问题都未能做到完美。日后,会着力修缮之。搜遍网上,讲解这个LCS问题的文章不计其数,但大多给读者一种并不友好的感觉,稍感晦涩,且代码也不够清晰。本文力图避免此些情况。力保...

2019-03-15 18:28:08 138

原创 LCS Revisited

LCS means 'Longest Common Subsequence' that means two non-empty strings are given; the longest subsequence that are common. Subsequence means removing 0 or more characters from a string.Now you are...

2019-03-15 16:56:28 107

转载 转:浅谈Trie树(字典树)

作者:xxy出处:http://www.cnblogs.com/TheRoadToTheGold/本文版权归作者和博客园共有,欢迎转载,但转载时请保留此段声明。 Trie树(字典树)一、引入字典是干啥的?查找字的。字典树自然也是起查找作用的。查找的是啥?单词。看以下几个题:1、给出n个单词和m个询问,每次询问一个单...

2019-03-02 15:34:58 237

原创 素因子去重@蓝桥

问题描述  给定一个正整数n,求一个正整数p,满足p仅包含n的所有素因子,且每个素因子的次数不大于1输入格式  一个整数,表示n输出格式  输出一行,包含一个整数p。样例输入1000样例输出10数据规模和约定  n&lt;=10^12  样例解释:n=1000=2^3*5*3,p=2*5=10利用唯一分解定理,将每个质因子相乘一次。#in...

2019-03-02 14:44:50 110

原创 唯一分解定理(分解质因子)

唯一分解定理:每个大于一的自然数均可写为质数的积,而且这些素因子按大小排列之后,写法只有一种方式。最简单的写法:#include &lt;iostream&gt;#include &lt;cstring&gt;#include &lt;cstdlib&gt;#define MAXN 10004using namespace std;int a[MAXN];int ...

2019-03-02 14:30:44 1012

原创 审美课@蓝桥

问题描述  《审美的历程》课上有n位学生,帅老师展示了m幅画,其中有些是梵高的作品,另外的都出自五岁小朋友之手。老师请同学们分辨哪些画的作者是梵高,但是老师自己并没有答案,因为这些画看上去都像是小朋友画的……老师只想知道,有多少对同学给出的答案完全相反,这样他就可以用这个数据去揭穿披着皇帝新衣的抽象艺术了(支持帅老师^_^)。  答案完全相反是指对每一幅画的判断都相反。输入格式  ...

2019-03-02 09:40:43 403

原创 1054 The Dominant Color@PTA

Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the ...

2018-10-23 19:36:24 90

原创 1051 Pop Sequence@PTA

Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of ...

2018-10-23 17:18:48 151

原创 1043 Is It a Binary Search Tree@PTA

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key. The right s...

2018-10-23 10:25:45 144

原创 1039 Course List for Student @PTA

Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes...

2018-10-17 19:11:01 93

原创 1033 To Fill or Not to Fill @PTA

With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different g...

2018-10-16 20:12:38 140

原创 C++大整数乘法 分治方法

求两个不超过200位的非负整数的积。Input有两行,每行是一个不超过200位的非负整数,没有多余的前导0。Output一行,即相乘后的结果。结果里不能有多余的前导0,即如果结果是342,那么就不能输出为0342。Sample Input1234567890098765432100Sample Output1219326311126352690000题...

2018-10-11 17:28:52 3687 1

原创 1025 PAT Ranking@PTA

先sort,再处理。final_rank和local_rank都是要根据前一个人的成绩得出,所以我们要额外定义记录前一个人成绩的变量;成绩相同,rank相同,反之,用已经计入排名的人数更新rank。#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;cstring&gt;#include &lt;string&g...

2018-10-10 19:09:04 143

原创 1021 Deepest Root@PTA

A graph which is connected and acyclic can be considered a tree. The hight of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root ...

2018-10-10 11:33:40 119

原创 1020 Tree Traversals@PTA

Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the co...

2018-10-09 19:44:22 135

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除