这章通过一个简单的例子,详细说明算法分析的步骤。
算法
问题
给定N个不同的整数,从中任意取出三个整数。请问有几种情况,使得取出的3个整数之和为0?
解法
可以使用暴力算法,代码如下:
1
2
3
4
5
6
7
8
9
for(int i=0;...
分类:
其他好文 时间:
2014-06-02 23:18:43
阅读次数:
320
本节主要通过建立数学模型,来计算算法的运行时间。
公式
算法的运行时间=所有操作的开销乘以操作的次数之和
开销
下表展示了各种操作所需要的时间(单位:纳秒)
整数加法 2.1
整数乘法 2.4
整数除法 5.4
浮点加法 4.6
浮点乘法 4.2
浮点除法 13.5
sin 91.3
...
分类:
其他好文 时间:
2014-06-01 10:42:00
阅读次数:
228
YUV到RGB:
int C = Y - 16;
int D = U - 128;
int E = V - 128;
int R = 298 * C + 409 * E + 128;
int G = 298 * C - 100 * D - 208 * E + 128;
int B = 298 * C + 516 * D + 128;
RGB到YUV:
...
分类:
其他好文 时间:
2014-06-03 00:42:16
阅读次数:
208
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.
Your algorithm should use only constant space....
分类:
其他好文 时间:
2014-06-01 10:41:23
阅读次数:
242
如题
#define USE_AND_MASKS
#include
#include
#include
#include
#pragma config OSC = INTIO67 //internal oscillator
#pragma config WDT = OFF //watchdog timer off
#pragma config LVP = OFF...
分类:
其他好文 时间:
2014-06-01 11:16:04
阅读次数:
246
从一开始学离散化就对它没有半毛钱好感,感觉出这种题纯属恶心人。
可以将Top x全部取出来然后离散化,缩点。剩下的就是伸展了,不再赘述。
也有人拿线段树过,一直没有想明白. . .
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma comment...
分类:
其他好文 时间:
2014-06-02 23:24:50
阅读次数:
338
字典树的删除操作:
1 没找到直接返回
2 找到叶子节点的时候,叶子节点的count标志清零,代表不是叶子节点了
3 如果当前节点没有其他孩子节点的时候,可以删除这个节点
判断是否需是叶子节点,就检查叶子节点的count标志就可以了。
判断是否有其他孩子节点就需要循环26个节点了,如果都为空,那么就没有其他孩子节点了。
#include
#include
#include ...
分类:
其他好文 时间:
2014-06-03 00:49:49
阅读次数:
279
作为入门,简单了解u-boot,为以后的深入学习打下基础。...
分类:
其他好文 时间:
2014-06-02 23:57:15
阅读次数:
341
【题目】
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.
【题意】
给定一个由0和1填充的二维矩阵,找一个全是1的最大矩形
【思路】
扫描二维矩阵,凡是扫到值为1的块时候,以当前块为矩形的左上角区块拓展,找最大矩阵。
先找出以每个“1”区块为左上角区块的最大矩形,然后求出最大全局的最大矩...
分类:
其他好文 时间:
2014-06-02 23:08:07
阅读次数:
289
SaveFileDialog saveFileDialog = new SaveFileDialog();
//打开的文件选择对话框上的标题
saveFileDialog.Title = "请选择文件";
//设置文件类型
saveFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
//设置默认文件类型显示顺序
saveFileDialog...
分类:
其他好文 时间:
2014-06-02 23:28:17
阅读次数:
346
方函数使用有两种方法:
以代码说明:
int main()
{
greater ig;
cout
cout()(4,6)
}
第一种方法:
greater ig的意思是产生一个名为ig 的对象,ig(4,6)则是调用器operate(),并给与两个参数4,6
第二种方法 :
greater()的意思是产生一个临时(没有名字的)...
分类:
其他好文 时间:
2014-06-01 10:49:10
阅读次数:
193
从四月以来,就一直跟着公司的师兄师姐们在做虚拟问诊...
分类:
其他好文 时间:
2014-06-03 00:03:06
阅读次数:
233
题目:
给定一个字符串,返回该串没有重复字符的最长子串。
分析:
1)子串:子串要求是连续的。
2)无重复,出现重复就断了,必须从新的位置开始。而新的位置就是重复字符第一次出现位置的下一个位置。
3)整个串可能没有一处重复。
那么,为了找出当前访问的字符是否出现过,要怎么做呢?当然是hash,O(1)的时间,而且既然是字符, 定义个255的hash table 就可以了,has...
分类:
其他好文 时间:
2014-06-01 10:48:31
阅读次数:
206
阻塞IO实现:
public class PlainEchoServer {
public void serve(int port) throws IOException {
final ServerSocket socket = new ServerSocket(port);
try {
while (true) {
final Socket clientSocket...
分类:
其他好文 时间:
2014-06-02 23:32:20
阅读次数:
357
【题目】
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
You should preserve the original relative order of the nodes in each of the two partitions.
For example,
Given 1->4->3-...
分类:
其他好文 时间:
2014-06-03 00:02:29
阅读次数:
270
题目链接:
http://poj.org/problem?id=2243
题目:
Knight Moves
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 10932
Accepted: 6171
Description
A friend of you...
分类:
其他好文 时间:
2014-06-02 23:31:39
阅读次数:
290
题目来源:1038 Bugs Integrated, Inc.
题意:最多能放多少个2*3的矩形
思路:状态压缩DP啊 初学 看着大牛的代码搞下来的 总算搞懂了 接下来会更轻松吧
3进制代表前2行的状态(i行和i-1行)1代表i-1行占位 2代表i行占位 i-1不管有没有占位都不会影响的0代表i行和i-1行都空闲
然后枚举状态dfs更新状态 话说就不能没写深搜了 有点不会了
#incl...
分类:
其他好文 时间:
2014-06-03 00:51:45
阅读次数:
340