- 博客(36)
- 收藏
- 关注
![](https://csdnimg.cn/release/blogv2/dist/pc/img/listFixedTop.png)
原创 刷题总结
POJ 3253 Huffman树 错误:结果超出了int的范围,应该用long long;而且printf("%lld",ans),注意是lld POJ 2686 Traveling by Stagecoach(DAG,状压dp) 题目大意:m个结点的无向图,每个结点表示一个城市,n张票,经过一条边消耗一张票,每张票有一个数值,经过一条边的时间为边的长度/票的数值。给定起点a,问终点b是否...
2017-12-30 19:38:32
257
原创 UVA 10820 Send a Table
所有可能的数对数量为N×N 所求的(x,y)一定满足x,y互素,否则设公约数为t,(x,y)可由(x/t,y/t)得到 若(x,y)互素,那么(y,x)也互素 若能求出满足1<=x<=N,1<=y<=x的互素的(x,y),那么经过对称即可得到所有的数对(可从N×N的二维图上来理解)求phi值时注意避免溢出#include <bits/stdc++
2018-05-20 13:08:02
165
原创 UVALive 5009 Error Curves
F(x)是一个凸函数(convex function) 用三分(ternary search)可求最小值点另外,EPS设置成>1e-9会WA#include <bits/stdc++.h>using namespace std;const int MAX_N = 10000 + 10;const double EPS = 1e-9;int n;int...
2018-05-19 17:15:07
182
原创 HDU 1402. A * B Problem Plus(FFT)
递归版本的FFT还是好写… 输出结果时,注意特殊情况0*0=0#include <iostream>#include <cstdio>#include <complex>#include <cstring>#include <cmath>using namespace std;typedef complex<d...
2018-04-02 14:41:30
202
原创 Codeforces EC #36 D. Almost Acyclic Graph
题目大意:给一个有向图,无多重边和自环,问能否至多去掉一条边,使这个图变为无环图。 先拓扑排序得到所有环上的结点。在这些结点中,选择入度为1的结点,尝试去掉指向它的边,看是否还有环;若无环,则符合题目要求。#include <bits/stdc++.h>using namespace std;const int MAX_N = 500 + 10;int n, m;ve...
2018-03-09 13:44:28
176
原创 Codeforces EC #36 C. Permute Digits
看上去不难,但一直在WA… 开始的算法是:从左往右构造结果res[i],在a没被选择的数字中,选择<=b[i]的最大值,如果选择的值< b[i],之后每一步都选择剩余数字中最大的。 问题在于:有可能选择了某个数字,导致之后不可能再构造出<=b的结果123456789123456789276193619183618162Output276193619�88755...
2018-03-09 00:10:49
173
原创 CodeForces Round #456(div 2) D-Fishes
这是个数学题a… 所有的r∗rr∗rr*r的scoop的数目为(n−r+1)∗(m−r+1)(n−r+1)∗(m−r+1)(n-r+1)*(m-r+1) 其中包含坐标(x,y)(x,y)(x,y)的scoop的数目为(坐标index从1开始)f(x,y)=(min(n+1,x+r)−max(x,r))∗(min(m+1,y+r)−max(y,r))f(x,y)=(min(n+1,x+r)−ma...
2018-03-08 21:47:49
209
原创 搜索
熟练一下搜索问题… POJ 3669 两种思路,一种是比较直接的想法,先把所有的袭击事件按时间排序,在BFS的过程中处理袭击事件;另一种是先预处理,再BFS。 写第一种时遇到的问题:在BFS中循环的结束条件是que.empty() || k >= M,若在队列为空时结束,则可能还有后续的袭击会摧毁之前能够到达的地方,因此最后需要处理完所有的袭击。排序后BFS#include &...
2018-03-08 15:56:18
121
原创 POJ 3237 树链剖分+线段树维护
和QTREE1类似,增加了NEGATE操作。 记几个踩到的坑: 1. 维护数据量为n(假设n为2的幂)的线段树的大小为2*n-1,此题线段树的数组大小应为2^15-1,在写的时候写成1&lt;&lt;15-1,C++的&lt;&lt;的优先级小于-,实际开出来是2^14。 2. 这样写之后没有数组越界的异常,而是不断的WA。全局变量的内存分配在堆区,虽然访问的范围超过了数组的大小,但是在...
2018-02-28 17:21:18
258
原创 Link Cut Tree
LCT用来维护有根树的森林。对任意结点v,Preferred Child(PC)的定义为:如果v没被访问过或者刚刚访问到v,则PC[v] = null;如果刚刚访问到v的孩子结点u所在的子树,则PC[v] = u。v到其preferred child(如果有)的边为preferred edge,preferred edge连接起来形成preferred path。需要表示的树(也就是直观上的树)称...
2018-02-25 21:21:00
615
原创 BBST
最近学习了一下各种BBST,简单总结一下。Splay Tree:区间操作强无敌...对[l,r)区间的操作,把l-1结点splay到树根,r结点splay到根的右结点,则根的右结点的左子树就是区间[l,r),然后对这棵子树进行操作。一个splay操作的均摊复杂度为O(logn)。常见操作:[l,r)区间每个数加a,每个结点维护一个加的数值的lazy_tag[l,r)区间翻转,每个结点维
2018-01-16 21:31:00
2178
原创 POJ 3468 区间更新的线段树、树状数组
题目:给一个数组A1,A2,…An,两个操作:对[a,b]区间内的每个数加C,查询[a,b]区间的和。 也就是实现能够高效区间更新和求和的线段树和树状数组。 线段树的每个结点维护两个值,一个是对区间内所有数都加上的值t,这样在区间更新时不必再向下更新。另一个是除t外区间内所有数的和s。若结点k的对应区间为[l,r),则区间内所有数的和为s+t*(r-l)。 能够实现高效区间更新的树状数组则比较
2018-01-09 19:31:28
302
原创 POJ 2104 分桶法/线段树
题目:给一个长度为n的数组a1,a2...an,1用平方分割来做,取块大小b=sqrt(n)把整个数组分块,每个块进行排序使块内有序。排序的复杂度为O((n/b)*(n/b)\*logb)=O(nlogn)然后求[i,j]区间第k大的数,[i,j]区间的首尾可能是部分块,是无序的,中间是有序的块。想着如何从分割后的块中高效找出第k大的数,对有序的块维护一个数对[l,r)表示第k大的数在本块
2018-01-09 18:09:29
284
原创 POJ 2991 线段树+向量旋转
向量(x,y)(x,y)逆时针旋转θ\theta:x′=x∗cosθ−y∗sinθx^{'}=x*cos\theta-y*sin\thetay′=x∗sinθ+y∗cosθy^{'}=x*sin\theta+y*cos\theta相对旋转量 语言的坑:printf("%.2lf %.2lf", vx[0], vy[0])导致超时的悲剧#include #include #include
2018-01-07 12:00:50
266
原创 8.20
题目:在一个无向图G=(V,E)G=(V,E)中,我们称D⊆VD \subseteq V为一个占优集,是指每个v∈Vv \in V都属于D或与D中一个节点为邻。在占优集问题中,输入为一个图和预算b,目标是求图中的一个规模不超过b的控制集——如果该集存在,证明该问题是NP-完全的。解:通过将顶点覆盖问题规约到此问题,来证明该问题是NP-完全的。对于图G=(V,E)G=(V,E),做处理转化为图G′=(
2016-11-25 18:02:36
310
原创 8.20
题目:在一个无向图G=(V,E)G=(V,E)中,我们称D⊆VD \subseteq V为一个占优集,是指每个v∈Vv \in V都属于D或与D中一个节点为邻。在占优集问题中,输入为一个图和预算b,目标是求图中的一个规模不超过b的控制集——如果该集存在,证明该问题是NP-完全的。解:通过将顶点覆盖问题规约到此问题,来证明该问题是NP-完全的。对于图G=(V,E)G=(V,E),做处理转化为图G′=(
2016-11-25 18:02:36
344
原创 LeetCode 122. Best Time to Buy and Sell Stock II
题目Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one a
2016-11-22 23:15:48
248
原创 LeetCode 121. Best Time to Buy and Sell Stock
题目 只买一次,找到最大收益Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of th
2016-11-22 23:07:24
327
原创 LeetCode 435. Non-overlapping Intervals
题目:给定一个区间数组,求可以去掉的使得剩余区间不重叠的最少区间数目。Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.Note: You may assume the i
2016-11-17 18:05:06
428
原创 LeetCode 45. Jump Game II
题目Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to re
2016-11-16 10:52:06
307
原创 LeetCode 44. Wildcard Matching
题目:字符串匹配问题Implement wildcard pattern matching with support for ‘?’ and ‘*’.‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence).The matching should c
2016-11-16 00:17:39
264
原创 LeetCode10. Regular Expression Matching
题目:简单正则表达式匹配Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover t
2016-11-08 19:56:14
318
原创 LeetCode25. Reverse Nodes in k-Group
题目:对一个链表的长度为k的块进行reverse,要求常数空间。Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out n
2016-11-08 19:36:57
284
原创 LeetCode144. Binary Tree Preorder Traversal
题目Given a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive solution is trivial, coul
2016-11-07 17:23:41
292
原创 LeetCode413. Arithmetic Slices
题目:A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmeti
2016-11-07 16:39:55
225
原创 LeetCode403. Frog Jump
题目:A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.Given
2016-11-07 15:29:23
328
原创 LeetCode112. Path Sum
题目Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and sum =
2016-11-07 15:26:00
223
原创 LeetCode329. Longest Increasing Path in a Matrix
题目:Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or mov
2016-11-07 14:28:20
382
原创 LeetCode 29. Divide Two Integers
题目:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.分析:这道题最基本的想法是进行减法,dividend-divisor,每一次成功减去之后divisor加倍(左移一位),如果不能减,并且divisor是加倍之后的,那么divi
2016-09-24 23:30:39
258
原创 LeetCode 199. Binary Tree Right Side View
题目:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example: Given the following binary tree, 1
2016-09-24 21:24:57
201
原创 LeetCode 15. 3Sum
题目:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain dup
2016-09-24 21:04:00
209
原创 LeetCode 327. Count of Range Sum
题目:Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j), i
2016-09-24 20:51:43
302
原创 HDOJ 1402. A * B Problem Plus (FFT快速傅里叶变换)
Problem Description Calculate A * B.Input Each line will contain two integers A and B. Process to end of file. Note: the length of each integer will not exceed 50000.Output For each case, outp...
2016-09-24 20:24:03
917
原创 LeetCode 11. Container With Most Water
题目:Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two
2016-09-24 18:06:37
218
原创 LeetCode 5 Longest Palindromic Substring
LeetCode 5 Longest Palindromic Substring题目:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palind
2016-09-14 09:11:59
240
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人