一, 最大流1)拆点①满足个体自身的限制POJ 3281 Dining最多多少奶牛可以选到心仪的食物和饮料。 因为每个奶牛对答案的贡献至多为一, 所以把每头奶牛拆成两个点, 连一条容量为一的边就可以了。SPOJ 962 Intergalactic Map这道题告诉我们网络流可以求 是否存在一条经过 ...
分类:
其他好文 时间:
2015-01-17 19:29:10
阅读次数:
161
题目:Given an array where elements are sorted in ascending order, convert it to a height balanced
BST.
思路:给出一个排序的数组,如何构造一个平衡二叉查找树?平衡二叉查找树要求任一结点的左右子树的高度差不能超过一,也叫做高度平衡树。如果让我们从一个排序数组中选取一个元素做树的根,我们会选择哪一个...
分类:
编程语言 时间:
2015-01-16 16:51:25
阅读次数:
237
题目大意:给定一棵树,每个节点有一个颜色,多次询问某条路径上颜色数量,强制在线
正解是块状数组,强制在线莫队会TLE到死,想AC这道题的不用看了
如果朴素的跑树上莫队其实并不难- - 但是强制在线
因此我们可以考虑强制在线莫队算法
将树分成O(n^1/3)块,每块大小O(n^2/3)
记录每两块之间的答案、每种颜色的出现次数和哪些点被记录到了答案中
每次查询先找到两端点所在块的端点的答...
分类:
编程语言 时间:
2015-01-16 16:42:48
阅读次数:
857
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Hide TagsDepth-first SearchLinked List 这....
分类:
其他好文 时间:
2015-01-15 21:47:04
阅读次数:
171
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* ...
分类:
其他好文 时间:
2015-01-14 15:35:32
阅读次数:
178
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *nex...
分类:
其他好文 时间:
2015-01-14 15:33:27
阅读次数:
169
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe...
分类:
其他好文 时间:
2015-01-14 15:33:12
阅读次数:
141
http://www.spoj.com/problems/DISUBSTR/题意:求字符串不同子串的数目。#include using namespace std;const int N=1005;void sort(int *x, int *y, int *sa, int n, int m) { ...
分类:
其他好文 时间:
2015-01-13 14:09:04
阅读次数:
126
1. 红黑树(RED-BLACK TREE)引言:红黑树(RBT)可以说是binary-search tree的非严格的平衡版本。与之相应的是平衡二叉树(Balanced Binary Tree)又称之为AVL树(因为是G.M. Adelson-Velsky 和 E.M. Landis在1962年发...
分类:
编程语言 时间:
2015-01-12 15:56:55
阅读次数:
357
题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.代码:oj测试通过Runtime:178 ms 1 # Definition...
分类:
编程语言 时间:
2015-01-11 20:18:51
阅读次数:
235