- 博客(10)
- 收藏
- 关注
原创 N后问题
public class NQueen1 { static int n; //皇后个数 static int[] x; //当前解 static long sum; //当前已找到的可行方案 public static long nQueen(int nn) { n = nn; sum = 0; x = new int[n...
2018-05-24 20:24:33 258
原创 01背包动态规划算法
public class 背包01Test { public static void knapsack(int[] v,int[] w,int c,int[][] m) { int n = v.length -1; int jmax = Math.min(w[n] - 1, c); for(int j = 0;j<=jmax;j++) m[n][j] = 0;...
2018-05-22 21:00:56 625
原创 网络编程(双方简单代码)
public class Clinet { public static void main(String[] args) { DatagramSocket ds = null; //和Socket相当 FileOutputStream fout = null; try { ds = new DatagramSocket(8889); //自己的端口号 byte[] b...
2018-05-20 21:39:08 2061
原创 五子棋
public class MainClass { // 创建棋盘 public void Create(char board[][]) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { board[i][j] = '+'; } } for (int i = 0; i ...
2018-05-20 21:21:59 501 1
原创 冒泡排序
public class Sort { /* * 冒泡排序 */ public static void main(String[] args) { int t; Scanner input = new Scanner(System.in); System.out.print("输入数的个数:"); int number = input.nextInt(); ...
2018-05-20 21:15:23 87
原创 多矩阵相乘的最优算法
public class BestNumber { public int[][] good(int[] p,int[][] m,int[][] s) { int n = p.length -1; for(int r = 2;r<=n;r++) { for(int i = 1;i<=n-r+1;i++) { int j = i+r-1; m[i][j] ...
2018-05-20 21:13:53 2888
原创 快速排序
public class Quick { /* * 快速排序 */ public void quickSort(int[] numbers, int start, int end) { if (start < end) { int base = numbers[start]; // 选定的基准值(第一个数值作为基准值) int temp; // 记录临时中间值 ...
2018-05-20 21:11:25 79
原创 二分搜索技术
public class TwoSearch { public int binarySearch(int[] a,int x,int n) { int left = 0; int right = n-1; while(left<=right) { int middle = (left+right)/2; if(x==a[midd...
2018-05-20 21:08:16 306
原创 合并排序
public class MergeSortTest { public static void merge(int[] c, int[] d, int l, int m, int r) { int i = l; int j = m + 1; int k = l; while (i <= m && j <= r) { if (c[i] <= ...
2018-05-20 21:02:27 236
原创 toString()的重载
一般用System.out.println();时,括号里面都默认调用toString()方法。例如:h = 20; System.out.println(h.toString()); 与 System.out.println(h);相同Hello类中:public Hello(int id, String name, int age) { super(); this.id = id;...
2018-05-13 19:08:15 3247 3
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人