- 博客(40)
- 收藏
- 关注
转载 莫队
排序巧妙优化复杂度,带来NOIP前的最后一丝宁静。几个活蹦乱跳的指针的跳跃次数,决定着莫队算法的优劣……目前的题型概括为三种:普通莫队,树形莫队以及带修莫队。若谈及入门,那么BZOJ2038的美妙袜子一题堪称顶尖。【例题一】袜子述大意:进行区间询问[l,r],输出该区间内随机抽两次抽到相同颜色袜子的概率。分析:首先考虑对于一个长度为n区间内的答案如何求解。题目要求An...
2018-07-30 14:25:05
360
转载 一个超级优美的gcd算法
int GCD(int a,int b){while(b^=a^=b^=a%=b);return a;}From https://www.cnblogs.com/Paul-Guderian/p/6933799.html
2018-07-30 12:47:41
2470
原创 # 线段树,树状数组,主席树
线段树定义性质实现(以求任意连续区间的最小值为例)树状数组定义性质实现主席树—-包括无修改和可修改。定义性质实现线段树定义 用一个满二叉树(叶子节点可以为空)来维护一个连续数组,整个树的所有叶子节点从左到右表示整个数组,每个非叶子节点表示其所有叶子的集合所描述的一个连续子数组的某一特性(最小值,最大值等)。性质...
2018-07-29 14:54:15
338
转载 CCF 201712-3
#include <bits/stdc++.h>using namespace std;char vMon[][4]={"","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","n
2018-03-09 21:22:26
243
原创 CCF 201712-2
问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针方向,3号小朋友坐在2号小朋友的顺时针方向,……,1号小朋友坐在n号小朋友的顺时针方向。 游戏开始,从1号小朋友开始顺时针报数,接下来每个小朋友的报数是上一个小朋友报的数加1。若一个小朋友报的数为k的倍数或其末位数(即数的个位)为k,则该小朋友被淘汰出局,不再参加以后的报数。当游戏中只剩下一个小朋...
2018-03-09 20:46:25
191
原创 CCF 201712-1
问题描述 给定n个数,请找出其中相差(差的绝对值)最小的两个数,输出它们的差值的绝对值。 输入格式 输入第一行包含一个整数n。 第二行包含n个正整数,相邻整数之间使用一个空格分隔。 输出格式 输出一个整数,表示答案。 样例输入 5 1 5 4 8 20 样例输出 1 样例说明 相差最小的两个数是5和4,它们之间的差值是1。 样例输入 5 9 3 ...
2018-03-09 20:42:22
172
原创 *[leetcode] 30.Substring with Concatenation of All Words
题目地址:https://leetcode.com/problems/substring-with-concatenation-of-all-words/discuss/题目描述: You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indi
2017-09-03 11:35:09
292
原创 [leetcode] 11 Container With Most Water
题目地址: https://leetcode.com/problems/container-with-most-water/description/题目描述: Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are
2017-09-02 22:15:48
192
原创 [leetcode] 668 Kth Smallest Number in Multiplication Table
题目地址:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/题目描述: Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number qui
2017-09-01 16:24:24
1398
原创 [leetcode] 10 Regular Expression Matching
题目地址:https://leetcode.com/problems/regular-expression-matching/description/题目描述: Implement regular expression matching with support for ‘.’ and ‘*’。
2017-09-01 11:32:23
240
原创 [leetcode] 3 Longest Substring Without Repeating Characters
题目地址:https://leetcode.com/problems/longest-substring-without-repeating-characters/description/题目描述:Given a string, find the length of the longest substring without repeating characters. Examples: Giv
2017-08-31 09:18:32
221
原创 算法作业23
题目地址:https://leetcode.com/problems/beautiful-arrangement/#/description 题目描述:Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N number
2017-06-28 23:43:37
288
原创 算法作业22
题目地址:https://leetcode.com/problems/super-washing-machines/#/description题目描述:You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty.For each move, you
2017-05-31 16:24:23
259
原创 算法作业21
题目地址:https://leetcode.com/problems/out-of-boundary-paths/#/description题目描述:There is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or c
2017-05-26 15:15:44
273
原创 算法作业20
题目地址:https://leetcode.com/problems/longest-increasing-path-in-a-matrix/#/description题目描述:Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to f
2017-05-23 20:53:23
670
原创 算法作业19
题目地址:https://leetcode.com/problems/max-sum-of-sub-matrix-no-larger-than-k/#/description题目描述:Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that
2017-05-23 16:34:49
418
原创 算法作业18
题目地址:https://leetcode.com/problems/subarray-sum-equals-k/#/description题目描述:Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.我
2017-05-23 11:59:28
218
原创 算法作业17
题目地址:https://leetcode.com/problems/erect-the-fence/#/description题目描述:There are some trees, where each tree is represented by (x,y) coordinate in a two-dimensional garden. Your job is to fence the entir
2017-05-23 01:06:42
243
原创 我的算法16
题目地址:https://leetcode.com/problems/maximum-product-of-word-lengths/#/description题目描述:Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not s
2017-05-03 14:01:10
296
原创 我的算法15
题目地址:https://leetcode.com/problems/student-attendance-record-ii/#/description 题目描述:Given a positive integer n, return the number of all possible attendance records with length n, which will be regarde
2017-04-25 23:43:32
217
原创 我的算法14
题目地址:https://leetcode.com/problems/candy/#/description题目描述:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the follo
2017-04-25 20:35:09
271
原创 算法作业13
题目地址:https://leetcode.com/problems/remove-duplicate-letters/#/description题目描述:Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only on
2017-04-25 20:05:45
246
原创 算法作业12
题目地址:https://leetcode.com/problems/ipo/#/description 题目描述:Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some
2017-04-18 13:24:20
365
原创 算法作业11
题目地址:https://leetcode.com/problems/patching-array/#/description 题目描述:Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] i
2017-04-08 19:43:34
239
原创 dijkstra最短路径算法
代码:#include<bits/stdc++.h>using namespace std;#define LEN 100005#define MAX INT_MAXint n;int node[LEN];int next[LEN];int cost[LEN];int dijkstra(int start,int end){ /*求一个图中从start到end的最短路径。
2017-03-29 22:45:30
300
原创 floyd最短路径算法
代码:#include<bits/stdc++.h>using namespace std;#define LEN 1001#define MAX INT_MAXint node[LEN][LEN];void floyd(int n){ /* 求一个图中任意一个点到另一个点的最短路径。 允许存在负权值,但不能存在负回路。 */ for(int k=0;k<n
2017-03-29 22:44:38
238
原创 flod求最小通路算法
代码:#include<bits/stdc++.h>using namespace std;#define MAX INT_MAXtypedef int CostType;struct Edge{ int v; int u; CostType cost; Edge(){} Edge(int x,int y,int c):v(x),u(y),cost(c){}
2017-03-29 22:43:45
761
原创 dijkstra求最小生成树
代码:#include<bits\stdc++.h>using namespace std;#define LEN 1002#define MAX INT_MAXint edge[LEN][LEN];int dijkstra(int n){ /*求最小生成树,edge是一个n*n数组, edge[i][j]表示i,j间的权值。为MAX表示无边。 */ in
2017-03-29 22:42:46
2494
原创 最小生成树kruskal算法
描述:无。 原理:最小生成树的相关定理。代码:#include<bits\stdc++.h>using namespace std;typedef int CostType;class Edge{public: int u; int v; CostType cost; Edge(){} Edge(int x,int y,CostType c):u(x),
2017-03-29 20:29:19
247
原创 我的算法10
该文章包含三题,为同一类题目。难道依次增加。第一题:题目地址:https://leetcode.com/problems/single-number/#/description 题目描述:Given an array of integers, every element appears twice except for one. Find that single one.我的代码:class So
2017-03-29 16:29:17
355
原创 最小树形图--朱刘算法
描述:最小树形图—-一个有向图的有根生成树中权最小的图。 原理:朱刘算法及相关定理。 代码 :#include<bits\stdc++.h> using namespace std; typedef int CostType;struct Edge{ int u; int v; CostType cost; Edge(){}; Edge(int x,in
2017-03-29 15:04:38
446
原创 我的算法9
题目地址:https://leetcode.com/problems/binary-tree-maximum-path-sum/#/description题目描述:Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some
2017-03-24 22:06:28
268
原创 我的算法8
题目地址:https://leetcode.com/problems/binary-tree-postorder-traversal/#/description题目描述:Given a binary tree, return the postorder traversal of its nodes’ values. Note: Recursive solution is trivial, coul
2017-03-24 21:25:18
268
原创 我的算法7
题目地址:https://leetcode.com/problems/serialize-and-deserialize-binary-tree/#/description题目描述:Serialization is the process of converting a data structure or object into a sequence of bits so that it can b
2017-03-24 19:30:31
320
原创 我的算法6
题目地址:https://leetcode.com/problems/diameter-of-binary-tree/#/description题目描述:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length
2017-03-24 17:48:07
340
原创 算法作业5
题目地址:https://leetcode.com/problems/continuous-subarray-sum/?tab=Description题目描述:Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous suba
2017-03-03 21:51:07
256
原创 算法作业4
题目地址:https://leetcode.com/problems/reverse-pairs/?tab=Description题目描述:Given an array nums, we call (i, j) an important reverse pair if i < j and nums[i] > 2*nums[j].You need to return the number of imp
2017-03-03 21:11:24
468
原创 算分作业3
题目地址:https://leetcode.com/problems/merge-k-sorted-lists/?tab=Description 题目描述:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.我的代码:/** * Definition f
2017-03-03 17:22:12
271
原创 算法作业2
题目地址: https://leetcode.com/problems/count-of-range-sum/?tab=Description 题目描述 :Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is d
2017-03-03 16:17:25
307
原创 算法作业1
题目地址 : https://leetcode.com/problems/median-of-two-sorted-arrays/?tab=Description 题目描述 : There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorte
2017-02-21 19:37:46
345
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人