月度归档:2012年02月

Win7 64位 IIS7.5配置PHP和MYSQL出现的问题及解决方法

无法载入mysql扩展,即无法连接MySQL

  • 把PHP文件夹中的libmysql.dll和libmcrypt.dll复制到C:/windows目录下,请注意,很多教程写的都是复制到C:/windows/system32,但是那些都是针对32位系统,而非64位Windows 7

全都设置好出现如下错误HTTP 错误 404.17 – Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。

  • 解决方法:打开应用程序池,选中后点右键–高级设置,将“启动32位应用程序”改为“true”

Shell Sort希尔排序Java实现

/**	希尔排序Java实现
 * 	by puladiao
 * 	http://blog.verypod.com
 */
 
import java.util.Random;

class ShellSort {
	int[] arr;

	public ShellSort(int num) {
		arr = new int[num];
	}
	
	// 将arr数组初始化为随机数数组
	public void randomArray() {
		Random rd = new Random();
		for (int i = 0; i < arr.length; i++) {
			arr[i] = rd.nextInt(arr.length * 2);
		}
	}

	// 将arr数组初始化为倒序数组
	public void reverseArray() {
		for (int i = 0; i < arr.length; i++) {
			arr[i] = arr.length - i;
		}
	}

	// 打印数组
	public void display() {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println("");
	}

	// 希尔排序
	public void shellSort() {
		int increment = 1;
		while (increment < arr.length) {
			increment = increment * 3 + 1;
		}
		increment = (increment - 1) / 3;
		while (increment >= 1) {
			for (int i = 0; i < increment; i++) {
				insertSort(i, increment);
			}
			display();
			increment = (increment - 1) / 3;
		}
	}
	
	// 插入排序,该方法会被希尔排序调用,该方法也可以直接使用,使用方法为 insertSort(0,1);
	// startIndex是排序起始索引,increment为增量,即元素之间的空间
	public void insertSort(int startIndex, int increment) {
		for (int i = startIndex + increment; i < arr.length; i += increment) {
			int j = i - increment;
			// System.out.println(i);
			int temp = arr[i];
			while (j >= startIndex && temp < arr[j]) {
				arr[j + increment] = arr[j];
				j -= increment;
			}
			arr[j + increment] = temp;
		}
	}
}

public class ShellSortApp {
	public static void main(String[] args) {
		ShellSort ss = new ShellSort(100);
		ss.reverseArray();
		ss.display();
		ss.shellSort();
		ss.display();
	}
}

Java数据结构和算法(第二版)第六章 编程作业

/**	Java数据结构和算法(第二版)第六章 编程作业
/**	Programming Projects in Chapter 6, Data Structure & Algorithms in Java 2nd Edition
 * 	by puladiao
 * 	http://blog.verypod.com
 */
// 6.3 递归解决N次方问题
public class Power {
	public static void main(String[] args) {
		System.out.println(doPower(2, 4));
	}

	public static long doPower(long base, long power) {
		long result = 1;
		if (power == 1) {
			result = base;
		} else {
			long factor = 1;
			if (power % 2 == 1) {
				factor = base;
			}
			power = power / 2;
			result = doPower(base, power) * doPower(base, power) * factor;
		}
		return result;
	}
}

// 6.4 递归解决背包问题
public class Knapsack {

	private static int[] arr = new int[] { 5, 6, 7, 8, 11 };

	public static void main(String[] args) {
		System.out.println(doKnapsack(arr.length-1, 20));
	}

	public static boolean doKnapsack(int n, int sum) {
		if (sum == 0) {
			return true;
		} 
		if (sum < 0 || (sum > 0 && n < 0)) {
			return false;
		} 
		if (doKnapsack(n - 1, sum - arr[n])) {
			System.out.println(arr[n]);
			return true;
		}
		System.out.printf("%d %d\n", arr[n],sum);
		return doKnapsack(n-1,sum);
	}
}

// 6.5 递归解决组合问题
public class Picker {
	static char[] arr = new char[] { 'A', 'B', 'C', 'D', 'E' };

	public static void main(String[] args) {
		Picker p = new Picker();
		p.pick(0, 5, 3, "");
	}

	// s为当前index,t为总数,n为组合数
	public void pick(int s,int t,int n,String str){
		if(n==1){
			for(int i=s;i<t+s;i++){
			System.out.println(str+arr[i]);
			}
		} else if(s<5) {
			//System.out.println(s);
			pick(s+1,t-1,n-1,str+arr[s]);
			pick(s+1,t-1,n,str);
		}
	}
}

Java解决Hanoi Tower(河内塔)问题

/**	Java解决Hanoi Tower(河内塔)问题
 * 	by puladiao
 * 	http://blog.verypod.com
 */
public class HanoiTower {

	public static void main(String[] args) {
		HanoiTower ht = new HanoiTower();
		ht.doMove(3, "a", "b", "c");
	}

	public void doMove(int number, String f, String i, String t) {
		if (number == 1) {
			System.out.printf("Move 1 from %s to %s\n", f, t);
		} else {
			doMove(number-1,f,t,i);
			System.out.printf("Move %d from %s to %s\n", number,f,t);
			doMove(number-1,i,f,t);
		}
	}
}

Java实现归并排序(MergeSort)

/**	归并排序Java实现
 *	MertSort using Java
 * 	by puladiao
 * 	http://blog.verypod.com
 */
class MergeSorter {
	private int nElems;
	private int[] theArray, workSpace;

	public MergeSorter(int[] theArray) {
		nElems = theArray.length;
		this.theArray = theArray;
	}

	public void MergeSort() {
		workSpace = new int[nElems];
		recMergeSort(0, nElems - 1);
	}

	private void recMergeSort(int lowerBound, int upperBound) {
		if (lowerBound == upperBound) {
			return;
		} else {
			int mid = (lowerBound + upperBound) / 2;
			recMergeSort(lowerBound, mid);
			recMergeSort(mid + 1, upperBound);
			merge(lowerBound, mid, upperBound);
		}
	}

	private void merge(int lowerBound, int mid, int upperBound) {
		int leftIndex, rightIndex, index;
		leftIndex = lowerBound;
		index = lowerBound;
		rightIndex = mid + 1;
		while (leftIndex <= mid && rightIndex <= upperBound) {
			if (theArray[leftIndex] < theArray[rightIndex]) {
				workSpace[index++] = theArray[leftIndex++];
			} else {
				workSpace[index++] = theArray[rightIndex++];
			}
		}
		while (leftIndex <= mid) {
			workSpace[index++] = theArray[leftIndex++];
		}
		while (rightIndex <= upperBound) {
			workSpace[index++] = theArray[rightIndex++];
		}
		for (int i = lowerBound; i <= upperBound; i++) {
			theArray[i] = workSpace[i];
		}
	}

	public void display() {
		for (int i = 0; i < nElems; i++) {
			System.out.print(theArray[i] + " ");
		}
		System.out.println("");
	}
}

public class MergeSortApp {
	public static void main(String[] args) {
		int[] arr = new int[] { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
		MergeSorter ms = new MergeSorter(arr);
		ms.display();
		ms.MergeSort();
		ms.display();
	}
}