`
superhack
  • 浏览: 32089 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论
文章列表
一个多线程下载与断点续传的demo...   import java.io.*; import java.net.*; import java.util.concurrent.*; public class Downloader3 { URL url; File des; File cfg; long size; long sum; int taskNum = 10; CountDownLatch latch; String path = "C:/Documents and Settings/Administrator/桌面/"; ...
主要是支持对优先队列中某元素属性值的修改(通过equals查找, 并替换新的引用), 可以用于A*算法框架... import java.util.*; @SuppressWarnings("unchecked") public class Heap<E extends Comparable<E>>{ private E[] heap; // E[0] is not used... private int num; private Comparator<E> cmp; public Heap() { ...
图遍历算法 ---- DFS & BFS...   public class GraphTraveler { LinkedList<Integer> open = new LinkedList<Integer>(); public void bfs(Graph g, int start) { int n = g.getVolume(); Graph tree = new Graph(n, false); boolean[] visited = new boolean[n]; Arrays.fill(visited, ...

快速排序

快速排序有很多注意事项...   public static void qsort(int[] a, int low, int high) { if (high < low + 2) return; int piv = low, end = high; while (low < high) { while (++low < end && a[low] <= a[piv]); while (--high > piv && a[high] >= a[piv]); if (low < hi ...
搜索算法学问不小...总结:1. 状态表示用整数最快, 可是转化状态的代码不好写, 用字符串挺爽的, 可有些地方涉及到数字运算, 代码又不自然, 整来整去, 还是用byte[]好了...性能没比字符串强多少...2. open表用LinkedList就挺好, 支持队列和堆栈两种模型, 这点在双向广度优先搜索时候挺方便, closed表千万别用List类型, 用HashMap或者HashSet性能上才可接受, 而且前者优于后者...3. 完美哈希函数, 也就是那个全排列的哈希函数, 能够不浪费一点儿空间, 实现一一映射, 函数的设计涉及到变进制数的概念, 数学的力量还是无比强大地...   ...

TCHS-12-950

Problem Statement      An army of k knights is going to try to kill an evil dragon. The dragon has h heads, and the knights must cut off all his heads one by one to complete their mission. Their fight will go as follows: First, the dragon will attack the knights as many times as he ...

TCHS-12-550

Problem Statement      Let's consider a standard six-sided die. Each side contains a distinct number between 1 and 6. We can represent a single die as a sequence of 6 digits in the following order: the number on its top side, bottom side, left, right, front and back sides. You are giv ...

TCHS-12-250

  Problem Statement      In some of the old historical chronicles the Indict system of chronology was used. Instead of a year, this system uses three integers, called indict, circle to the Sun, and circle to the Moon. Let's denote them as indict, circleSun, circleMoon.   Each of these ...

TCHS-11-1000

Problem Statement      You have beads of several different colors that are to be placed on a string, with the requirement that for any group of three adjacent beads, all three must have different colors. You are given a int[] beads indicating how many of each color bead you have. Th ...

TCHS-11-500

Problem Statement      You are playing a game with some friends. The game is played on a rectangular chess board where each cell may be either empty or occupied by a rook. You are given a String[] board representing the layout of the board. Each character of each element of board repr ...

TCHS-11-250

Problem Statement      You are given a String[] blocks representing the layout of a city. Each character of each element of blocks represents one city block. A 'B' character represents a bus stop, and a '-' represents all other spaces. The fare for traveling on the bus is equal to t ...

TCHS-10-1000

Problem Statement      You have a string s containing only ones and zeroes. Your goal is to make all the characters in s equal using a minimal number of operations. A single operation consists of inverting all the characters in a contiguous substring of s. Inverting a character means ...

TCHS-10-500

Problem Statement      There are several cannons located on a plane. Each cannon is represented as a point, and can shoot in one of four directions: left, right, up or down. Given the coordinates of the cannons, assign a direction to each one such that no cannon shoots another cannon. ...

TCHS-10-250

Problem Statement      Given a int[] x and a percentile p (between 0 and 100, inclusive), find the smallest element y in x such that at least p percent of the elements in x are less than or equal to y. Definition      Class: Fractile Method: fractile Pa ...

TCHS-9-1000

Problem Statement      Consider a square n x n matrix A. The cell Ai,j is equal to the product i * j (i, j are 1-based). Let's create a one-dimensional array which contains all the elements of the matrix A. The length of this array will be equal to n2. Sort this array and return the ...
Global site tag (gtag.js) - Google Analytics