码迷,mamicode.com
首页 >  
搜索关键字:iii    ( 1515个结果
HDU 5266 pog loves szh III ( LCA + SegTree||RMQ )
pog loves szh IIITime Limit: 12000/6000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 470Accepted Submission(s): 97P...
分类:其他好文   时间:2015-06-09 06:06:23    阅读次数:104
HDU5266---pog loves szh III (线段树+LCA)
题意:N个点的有向树, Q次询问, 每次询问区间[L, R]内所有点的LCA。大致做法:线段树每个点保存它的孩子的LCA值, 对于每一次询问只需要 在线段树查询即可。 1 #include 2 using namespace std; 3 const int MAXN = 3e5+10; ...
分类:其他好文   时间:2015-06-08 23:09:00    阅读次数:257
Leetcode题解(4):L216/Combination Sum III
L216: Combination Sum III   Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of number...
分类:其他好文   时间:2015-06-08 15:03:38    阅读次数:116
HDU 5266 pog loves szh III (线段树+在线LCA转RMQ)
题目地址:HDU 5266 这题用转RMQ求LCA的方法来做的非常简单,只需要找到l-r区间内的dfs序最大的和最小的就可以,那么用线段树或者RMQ维护一下区间最值就可以了。然后就是找dfs序最大的点和dfs序最小的点的最近公共祖先了。 代码如下:#include #include #include #include ...
分类:其他好文   时间:2015-06-08 14:59:13    阅读次数:133
[LeetCode] Contains Duplicate(II,III)
Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if...
分类:其他好文   时间:2015-06-06 18:15:25    阅读次数:494
LeetCode Contains Duplicate III
LeetCode Contains Duplicate III题目思路我的方法是先用一个结构体,存下每个数字的值和其原坐标; 然后根据值大小排序; 接着遍历每一个数字num[i].val; 利用二分查找找到刚好比num[i].val - t - 1大的数字的坐标; 然后根据坐标判断是否存在值即可; 关于二分查找可见:Binary Search代码struct num { int p...
分类:其他好文   时间:2015-06-06 09:09:47    阅读次数:96
[LeetCode] Two Sum III - Data structure Design
Problem Description:Design and implement a TwoSum class. It should support the following operations: add and find.add - Add the number to an internal ...
分类:其他好文   时间:2015-06-05 13:57:47    阅读次数:168
Contains Duplicate III
Contains Duplicate III问题:Given an array of integers, find out whether there are two distinct indicesiandjin the array such that the difference between...
分类:其他好文   时间:2015-06-05 12:13:12    阅读次数:127
LightOJ - 1248 Dice (III) 期望 + dp
题目大意:给出一个n面的色子,问看到每个面的投掷次数期望是多少解题思路:水题啊,竟然被卡了那么久,也是醉了,给题目所给的那个样例误导了。。。不怪那个 怪自己太弱了,还得继续训练啊。。。设dp[i]表示扔到i个不同面的期望,那么 dp[i + 1] = i / n * dp[i + 1] + (n - i) / n * dp[i] + 1 整理得 dp[i + 1] = n / (n - i)...
分类:其他好文   时间:2015-06-05 10:20:03    阅读次数:120
LeetCode "Contains Duplicate III"
Lesson learnt: std::multiset is a heap structure supporting random removal...class Solution { public: bool containsNearbyAlmostDuplicate(vec...
分类:其他好文   时间:2015-06-05 08:44:00    阅读次数:129
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!