2013年10月1日
摘要: hdu1007, 算法课的一个例子,计算几何和分治法。在hdu上ac了, zoj上死活过不了。附代码: 1 /* 2 3 */ 4 #include 5 #include 6 #include 7 #include 8 #define MAX 101000 9 10 typedef struct point 11 { 12 int id; 13 double x; 14 double y; 15 } POINT; 16 17 POINT sorted_x[MAX], sorted_y[MAX], sub_y[MAX]; 18 POINT... 阅读全文
posted @ 2013-10-01 16:44 leiatpku 阅读(207) 评论(0) 推荐(0) 编辑
  2013年7月2日
摘要: 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 */10 public class Solution {11 public boolean isSameTree(TreeNode p, TreeNode q) {12 // Start typing your... 阅读全文
posted @ 2013-07-02 10:21 leiatpku 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 1 public class Solution { 2 public int sqrt(int x) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 double result = x; 6 7 while (Math.abs(result * result - x) > 0.0001) 8 { 9 result = (result + x / re... 阅读全文
posted @ 2013-07-02 09:29 leiatpku 阅读(235) 评论(0) 推荐(0) 编辑
  2013年7月1日
摘要: 1 public class Solution { 2 public double pow(double x, int n) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 double result = 1.0; 6 if (n >= 0) 7 return cal(x, n); 8 else 9 {10 n = -1 * n;... 阅读全文
posted @ 2013-07-01 10:58 leiatpku 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 1 public class Solution { 2 public int[] twoSum(int[] numbers, int target) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 int result[] = new int[2]; 6 int tags = 0; 7 for (int i = 0; i < numbers.length && tags == 0; i++) ... 阅读全文
posted @ 2013-07-01 10:28 leiatpku 阅读(156) 评论(0) 推荐(0) 编辑