题目要求比其高的邻居要比本身的奖励多,那么最少也要多一个,所有我们可以找到所有的凹点,凹点如下三种情形。
找到所有的凹点后,我们就可以从凹点处开始向左右两个方向依次查找递增序列,其中每个高的都要比相邻的矮的多一个,比如1,2,5,4.我们找到凹点为1 和4,那么从1开始向左没有其他点,我们向右,依次得到2 比1高,2的糖果应该是1的基础上加1,为2, 5比2高,5的糖果是在2的基础上加1...
分类:
编程语言 时间:
2014-07-18 23:14:20
阅读次数:
373
类似于二叉树的三种遍历,我们可以基于遍历的模板做很多额外的事情,图的两种遍历,深度和广度模板同样也可以做很多额外的事情,这里举例利用深度优先遍历的模板来进行复制,深度优先中,我们先访问第一个结点,接着访问第一个邻接点,再访问邻节点的邻节点。。。。
class Solution:
# @param node, a undirected graph node
# @return a ...
分类:
编程语言 时间:
2014-07-18 23:11:00
阅读次数:
331
/** \brief poj 1502--Dijkstra
*
* \ date 2014/7/15
* \ state AC
* *
*/
#include
#include
#include
#include
using namespace std;
#define inf 0x03f3f3f3f
const int MAXN=101;
int n;
int co...
分类:
其他好文 时间:
2014-07-18 21:22:31
阅读次数:
192
问题的思路是这样:
循环取头部合并,其实也可以换个角度来看,就是将后面的链表结点,一次隔空插入到第一部分的链表中。
class Solution:
# @param head, a ListNode
# @return nothing
def reorderList(self, head):
if None == head or None == ...
分类:
编程语言 时间:
2014-07-16 17:23:30
阅读次数:
207
题目分析见这里
class Solution:
# @param head, a ListNode
# @return a list node
def detectCycle(self, head):
if None == head or None == head.next:
return None
pfast = ...
分类:
编程语言 时间:
2014-07-16 17:18:53
阅读次数:
248
// Algorithm implementation -*- C++ -*-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,// 2010, 2011// Free Software Foundation,...
分类:
其他好文 时间:
2014-07-16 16:56:01
阅读次数:
375
题目:poj2446
题意:给出一个m*n的矩阵,其中有的地方有坑,然后用1*2的纸片去覆盖图,纸片不能重复,能够把出了坑的地方其他全部覆盖的话输出YES,否则NO
分析:有一道二分图经典题目,当然难点还是建图,一直没有思路,早上来忽然想到可以用(i-1)*m+j 吧矩阵中每个点转化为一个数,然后相邻连接起来建图,匈牙利,但是不知道为什么不对?求大神解释、还是理解不够深。
...
分类:
其他好文 时间:
2014-07-16 14:44:47
阅读次数:
230
/*
* poj1251-- Kruskal
* date 2014/7/15
* state AC
*/
#include
#include
#include
#include
#include
using namespace std;
int const MAXN=30+100;
int u[MAXN];
int v[MAXN];
int w[MAXN+50];
int p[...
分类:
其他好文 时间:
2014-07-16 10:34:41
阅读次数:
180
class Solution:
# @param head, a ListNode
# @return a boolean
def hasCycle(self, head):
if None == head or None == head.next:
return False
pfast = head
...
分类:
编程语言 时间:
2014-07-16 09:50:21
阅读次数:
271
Ultra-QuickSort
Description
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 eleme...
分类:
其他好文 时间:
2014-07-16 09:00:13
阅读次数:
240