题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083题目意思:如果给出 instruction 就需要输出对应的16-bit binary code,给出16-bit binary code 就需要输出对应的instruction。 由于不会截取的....
分类:
其他好文 时间:
2014-10-27 00:15:41
阅读次数:
354
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".SOLUTION:指针指到两个字符串的末尾,不断往前推进,用carr...
分类:
其他好文 时间:
2014-10-26 22:40:47
阅读次数:
339
Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets m...
分类:
其他好文 时间:
2014-10-26 22:31:27
阅读次数:
438
Merge IntervalsGiven a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,1...
分类:
其他好文 时间:
2014-10-26 21:04:46
阅读次数:
199
可以暴力递归求解,应该不会TLE,但是我们考虑记忆化优化。设f(i,j)表示第i个数为j时的方案数。f(i,j)=f(1,j-1)+f(2,j-1)+……+f(i-1,j-1) (4>=j>=1),从f(n,4)开始递归求解就行。但是考虑到状态最多只有n*4种,所以记忆化掉吧。初始化:f(i,1)=...
分类:
其他好文 时间:
2014-10-26 19:35:09
阅读次数:
183
设答案为f(n),我们显然可以暴力地递归求解:f(n)=f(1)+f(2)+……+f(n/2)。但是n=1000,显然会超时。考虑状态最多可能会有n种,经过大量的重复计算,所以可以记忆下来,减少不必要的计算。 1 #include 2 using namespace std; 3 int n; 4 ...
分类:
其他好文 时间:
2014-10-26 18:20:58
阅读次数:
295
对于一对数(p,q),若它们的gcd为x0,lcm为y0,则:p*q/x0=y0,即q=x0*y0/p,由于p、q是正整数,所以p、q都必须是x0*y0的约数。所以O(sqrt(x0*y0))地枚举约数,依次用gcd判断。 1 #include 2 #include 3 using namespac...
分类:
其他好文 时间:
2014-10-26 18:12:47
阅读次数:
231
【题目】
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like
this: (you may want to display this pattern in a fixed font for better legibility)
P A H N
...
分类:
其他好文 时间:
2014-10-26 16:57:47
阅读次数:
182
DP、KMP什么的都太高大上了,自己想了个朴素的遍历方法。
【题目】
Given a string S,
find the longest palindromic substring in S.
You may assume that the maximum length of S is
1000, and there exists one unique longest palin...
分类:
其他好文 时间:
2014-10-26 15:37:32
阅读次数:
249
【题目】
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it...
分类:
其他好文 时间:
2014-10-26 14:21:29
阅读次数:
243