【题目】
Given a singly linked list L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You must do this in-place without altering the nodes' values.
For example,
Given {1,2,3,4}, reorder it to {1,4,2,3}.
【题意】
给定一个链表L: L0→L1→…→Ln-1→Ln,对他重新排序成L...
分类:
其他好文 时间:
2014-06-30 10:11:14
阅读次数:
158
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
给定一个罗马数字,把它转换成一个整数。
把罗马数字字符串转换成字符数组先,如下表,每个数字仅对应一个字符,而且字符不一样。故可从头开始取值进行对应。
The R...
分类:
其他好文 时间:
2014-06-30 09:52:40
阅读次数:
251
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
给定一个整数,把它转换成罗马数字。
输入可以保证在1到3999之间。
下图是转换规则。
1
2
3
4
...
分类:
其他好文 时间:
2014-06-30 09:28:05
阅读次数:
308
题目链接:uva 1436 - Counting heaps
题目大意:给出一个树的形状,现在为这棵树标号,保证根节点的标号值比子节点的标号值大,问有多少种标号树。
解题思路:和村名排队的思路是一只的uva11174,最后问题只和树德结构有直接关系,f(root)=(s(root)?1)!(s(1)?s(2)???s(n)
但是给定的取模数不是质数,所以不能用逆元做,只能将分子分...
分类:
其他好文 时间:
2014-06-30 09:17:52
阅读次数:
272
题目:
* 给定一个数组input[] ,如果数组长度n为奇数,
* 则将数组中最大的元素放到 output[] 数组最中间的位置,
* 如果数组长度n为偶数,
* 则将数组中最大的元素放到 output[] 数组中间两个位置偏右的那个位置上,
* 然后再按从大到小的顺序,依次在第一个位置的两边,
* 按照一左一右的顺序,依次存放剩下的数。
* 例如:
* inp...
分类:
其他好文 时间:
2014-06-30 08:34:41
阅读次数:
179
题意:给你n个矩阵求覆盖面积。
思路:看了别人的结题报告
给定一个矩形的左下角坐标和右上角坐标分别为:(x1,y1)、(x2,y2),对这样的一个矩形,我们构造两条线段,一条定位在x1,它在y坐标的区间是[y1,y2],并且给定一个cover域值为1;另一条线段定位在x2,区间一样是[y1,y2],给定它一个cover值为-1。根据这样的方法对每个矩形都构造两个线段,最后将所有的线段根据所定位...
分类:
其他好文 时间:
2014-06-30 00:31:13
阅读次数:
242
【题目】
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
Follow up:
Can you solve it without using extra space?
【题意】
给定一个单向链表,如果链表有环,则返回环开始的位置。
【思路】
仍然是维护两个指针, p1, p2, p1每次走一步, p2每次走两步
...
分类:
其他好文 时间:
2014-06-29 23:59:21
阅读次数:
354
UVA 10710 - Chinese Shuffle
题目链接
题意:给定n张牌,完美洗牌n - 1次,问是否会变回原来的序列
思路:完美洗牌:
假设有a1a2a3...anb1b2b3...bn的牌,设每张牌原来的位置为x,那么完美洗牌一次后,前n张牌分别到2 x位置,后n张分别到1, 3, 5..也就是2
x % (2 n + 1)的位置,因此每张牌位置变为2 x % ...
分类:
其他好文 时间:
2014-06-29 23:53:10
阅读次数:
295
【题目】
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
【题意】
给定一个整数以外,其中除了一个整数只出现一次以外...
分类:
其他好文 时间:
2014-06-29 22:52:35
阅读次数:
246
【题目】
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
Return a deep copy of the list.
【题意】
给定一个链表,每个节点除了next指针外,还有一个random指针,指向任意的节点。
要求,复制这样的一个链表
【思路】
思路...
分类:
其他好文 时间:
2014-06-29 20:41:21
阅读次数:
232