自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

小猪爱拱地

勤奋和毅力是通向成功的阶梯

  • 博客(13)
  • 资源 (1)
  • 收藏
  • 关注

原创 判断线段相交的实现

根据算法导论33章里的算法实现。算法如下:代码如下:#include struct point { int x; int y;};int cross_product(struct point *p1, struct point *p2){ return p1->x * p2->y - p1->y * p2->x;}int on_segment(st

2016-04-25 11:27:34 643

转载 awk 中使用 OFS.

awk的OFS不能够直接在print中打印,需要用逗号分隔后打印 awk  'BEGIN{FS=":";OFS="=";} {print $3,$4;}' /etc/passwdhttp://www.cnblogs.com/welkinwalker/archive/2011/08/12/2135982.html

2016-04-23 23:27:46 2401

转载 $IFS

The IFS is a special shell variable.You can change the value of IFS as per your requirments.The Internal Field Separator (IFS) that is used for word splitting after expansion and to split lines into w

2016-04-23 23:19:02 543

原创 如何保存grep 结果里面的换行符?

先看下面的命令:~$ grep bash /etc/passwdroot:x:0:0:root:/root:/bin/bashguest-rwf0fx:x:116:125:Guest,,,:/tmp/guest-rwf0fx:/bin/bash但是,如果把结果保存到变量里面:~$ result=$(grep  bash /etc/passwd)charles@xiaotao:

2016-04-23 23:09:49 9535

原创 查找有向图中的环

根据“算法导论”中的DFS算法实现。如下:#include enum{ WHITE, GRAY, BLACK};struct vertex{ int color; int d, f; int parent;};int time = 0;void dfs_visit(int matrix[][6], struct vertex *v, int index);

2016-04-20 23:26:12 3800 2

原创 计算fibnacci 级数的几种方法

1. 直接计算(递归)int fib(int x){ if (x <= 1) return x; return fib(x-1)+fib(x-2);}时间复杂度: O(2^n)2. 使用动态规划:int fib(int n){ if( n == 0 || n == 1) { return n;

2016-04-15 08:16:04 849

原创 Modular exponentiation

1. 递归实现:unsigned long long modular_pow_recursive(unsigned long long base, int exponent, int modulus){ if (modulus == 1) { return 0; } if(exponent == 0) {

2016-04-15 00:42:10 766

转载 Fast modular exponentiation

How can we calculate A^B mod C quickly if B is a power of 2 ?Using modular multiplication rules:i.e. A^2 mod C = (A * A) mod C = ((A mod C) * (A mod C)) mod CWe can use this to calculate 7

2016-04-14 00:27:23 909

转载 Modular arithmetic

1. An introductionWhen we divide two integers we will have an equation that looks like thefollowing:A/B = Q remainder RA is the dividendB is the divisorQ is the quotientR is th

2016-04-14 00:08:01 918

原创 Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of ea

2016-04-10 14:34:27 426

原创 求和最大的子矩阵

问题是,给定一个矩阵,求和最大的子矩阵。比如,下面的矩阵:和最大的是蓝线框对应的矩阵(和为29)。解决思路为,把矩阵每行的值累加到一个一维数组上面,然后去求那个一维数组里面和最大的连续子数组。如果使用 kadane算法,时间复杂度为 O(n^3).实现如下://#include #include struct max_array{ int start; in

2016-04-09 09:56:11 1191

原创 在程序中表示负无穷大的数

有时候需要在代码中给某个变量赋一个富无穷大的数值。一种方法是使用系统提供的宏, 比如, INT_MIN 78 /* Minimum and maximum values a `signed int' can hold. */ 79 # define INT_MIN (-INT_MAX - 1) 80 # define INT_MAX 2147483647使用时包含头文件

2016-04-07 07:09:49 2004

原创 Kadane算法(值最大的连续子数组)

算法的介绍可以看下面的连接:https://en.wikipedia.org/wiki/Maximum_subarray_problem下面是一个 C的实现#include int find_maximum_subarray(int *array, int size){ int start = 0, end = 0; int sum = INT_MIN; int tmp_

2016-04-06 08:26:18 2676

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除