HDU 1394 Minimum Inversion Number (数据结构-线段树)
题目大意:
求逆序数。也就是给你一个序列,每次求逆序数,然再把第一个数放到这个序列的末尾,构成新的序列。问你这n个序列的最小的逆序数。
解题思路:
1、对于每个序列,其原来的逆序数记为 pre , 如果当前把该序列 第一个数 a[0] 移动到尾部,那么新序列的逆序数为 pre-a[i]+(n-a[i]-1)
因为序列中比a[i]大的数有 n-a[i]-1 个,比a[i]小的有 a[i]个。
因此只需求出...
分类:
其他好文 时间:
2014-05-12 07:07:01
阅读次数:
301
<!doctypehtml>
<html>
<head>
<title>益司CMS-PC与手机建站集成</title>
<metaname="viewport"content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<linkhref="__PUBLIC__/bootstrap/css/bootstrap...
分类:
其他好文 时间:
2014-05-12 03:54:09
阅读次数:
253
<!doctypehtml>
<html>
<head>
<title>益司CMS-PC与手机建站集成</title>
<metaname="viewport"content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<linkhref="__PUBLIC__/bootstrap/css/bootstrap...
分类:
其他好文 时间:
2014-05-12 03:13:07
阅读次数:
236
1 //@author: Zou Xiaohang 2 //@describe: this class
is like AtomicMarkableReference which is in java concurrent package. 3 //
remember th...
分类:
编程语言 时间:
2014-05-12 01:24:20
阅读次数:
504
算法旨在用尽可能简单的思路解决问题,理解算法也应该是一个越看越简单的过程,当你看到算法里的一串概念,或者一大坨代码,第一感觉是复杂,此时不妨从例子入手,通过一个简单的例子,并编程实现,这个过程其实就可以理解清楚算法里的最重要的思想,之后扩展,对算法的引理或者更复杂的情况,对算法进行改进。最后,再考虑时间和空间复杂度的问题。
了解这个算法是源于在Network Alignment问题...
分类:
其他好文 时间:
2014-05-11 22:31:54
阅读次数:
573
Given a linked list, reverse the nodes of a
linked listkat a time and return its modified list.If the number of nodes is not
a multiple ofkthen left-o...
分类:
其他好文 时间:
2014-05-11 18:15:52
阅读次数:
300
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie
Single Number II
Total Accepted: 14224 Total
Submissions: 43648
Given an array of integers, every element appears three ti...
分类:
其他好文 时间:
2014-05-11 03:54:46
阅读次数:
317
题目
Given a binary tree, find the maximum path sum.
The path may start and end at any node in the tree.
For example:
Given the below binary tree,...
分类:
其他好文 时间:
2014-05-11 03:25:24
阅读次数:
298
题意:在一组数组中除一个元素外其它元素都出现两次,找出这个元素
思路:位运算。异或。因为异或操作可以交换元素的顺序,所以元素异或的顺序没影响,
最后出现再次的元素都会被异或掉,相当于0和只出现一次的那个元素异或,结果还是那个元素
推广:这个方法也适合于出现其它元素都出现偶数次,而要找的元素出现奇数次的情况
相关题目:Single Number II
class Solution...
分类:
其他好文 时间:
2014-05-11 02:37:42
阅读次数:
397
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie
Maximum Depth of Binary Tree
Total Accepted: 16605 Total
Submissions: 38287
Given a binary tree, find its maximum depth.
...
分类:
其他好文 时间:
2014-05-11 01:58:31
阅读次数:
441