N头牛排成一列,每头牛的听力是Vi,每头牛的位置Pi,任意两头牛i,j相互交流时两头牛都至少需要发出声音的大小为max(Vi,Vj) * |Pi-Pj|,求这N头牛两两交流总共发出的声音大小是多少。N,V,P都是1-20000的范围。
这题首先对Vi从小到大进行排序,排序过后就可以依次计算i,将所有比Vi小的牛到i之间的距离之和乘以Vi得到Ri,然后累加Ri就是最终结果...
分类:
其他好文 时间:
2014-07-25 11:27:51
阅读次数:
193
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
比较简单,就是转化成中序遍历即可,访问顺序是中序遍历左子树,根节点,中序遍历右子树
Python编程的时候需要注意,要在返回单一数字的时候加...
分类:
编程语言 时间:
2014-07-25 11:07:51
阅读次数:
221
二叉查找树(Binary Search Tree)在很多情况下可以良好的工作,但它的限制是最坏情况下的渐进运行时间为 O(n)。平衡查找树(Balanced Search Tree)的设计则是保证其高度在最坏的情况下为 O(log n),其插入、删除和查找可以实现渐进运行时间 O(log n)。本文...
分类:
其他好文 时间:
2014-07-24 14:44:35
阅读次数:
282
解决办法:vi /etc/sysconfig/selinux将:SELINUX=enforcing改为:#SELINUX=enforcingSELINUX=disabled 重启linux
分类:
系统相关 时间:
2014-07-24 14:42:05
阅读次数:
245
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
const int maxn =10000+5;
const int ma...
分类:
其他好文 时间:
2014-07-24 10:45:34
阅读次数:
230
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...
分类:
其他好文 时间:
2014-07-24 10:06:33
阅读次数:
191
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ...
分类:
其他好文 时间:
2014-07-24 10:04:33
阅读次数:
214
实现: 1 #ifndef BINARY_SEARCH_TREE_H 2 #define BINARY_SEARCH_TREE_H 3 4 #include "dsexceptions.h" 5 #include // For NULL 6 using namespace st...
分类:
其他好文 时间:
2014-07-24 10:03:33
阅读次数:
398
实现: 1 #ifndef AVL_TREE_H 2 #define AVL_TREE_H 3 4 #include "dsexceptions.h" 5 #include // For NULL 6 using namespace std; 7 8 // AvlTree...
分类:
其他好文 时间:
2014-07-24 10:01:43
阅读次数:
317
题目:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flatten...
分类:
编程语言 时间:
2014-07-24 09:55:43
阅读次数:
211