自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(90)
  • 收藏
  • 关注

转载 String、Date、Calendar之间的转换

原博客地址 Calendar 转化 StringCalendar calendat = Calendar.getInstance();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");String dateStr = sdf.format(calendar.getTime()); ```String 转化Calendar``

2017-07-22 16:28:17 431

原创 java.util.Date类型日期增减的方法

public static void main(String[] args) { Calendar c = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); c.set(Calendar.YEAR, 2013); c.set(Calendar.MONTH

2017-07-22 15:58:12 913

原创 OpenCV配置指南

第一次配置 OpenCV 比较繁琐,而 OpenCV Library 提供了丰富而详细的说明文档,虽然文档内容多基于 Visual Studio 2010,但是与之后的版本在配置上没有太大差别,这里以 Visual Studio 2013 + OpenCV2.4.13 为环境做配置详解。一、下载和解压 OpenCV前往 OpenCV 官网,找到RELEASES,选择合适的版本,其中有 OpenCV2

2017-06-22 01:41:31 582

原创 socket通道小例子

用这个小例子,实现客户端提交加法数据,服务端计算结果并返回给客户端。 服务端代码package me.zhengzx.nio;import java.io.IOException;import java.net.InetSocketAddress;import java.nio.ByteBuffer;import java.nio.IntBuffer;import java.nio.cha

2017-06-20 01:59:11 333

原创 Java NIO 通道

一、通道基础通道(Channel)是 java.nio 的第二个主要创新。他们既不是一个扩展也不是一个增强,而是全新、极好的Java IO 示例,提供与 IO 服务的直接连接。Channel 用于在字节缓冲区和位于通道另一侧的实体(通常是一个文件或套接字)之间有效地数据传输。通道可以形象地比喻为银行出纳窗口使用的气动导管。你的薪水支票就是你要传送的信息,载体(Carrier)就好比一个缓冲区。你先填

2017-06-20 01:58:03 307

原创 Java NIO 缓冲区

一、缓冲区基础概念上,缓冲区是包在一个对象内的基本数据元素数组。Buffer 类相比一个简单数组的有点是它将关于数据的数据内容和信息包含在一个单一的对象中。Buffer 类以及它专有的子类定义了一个用于处理数据缓冲区的 API。所有的缓冲区都具有四个属性来提供关于其所包含的数据元素的信息。它们是: 1. 容量(Capacity) 缓冲区能够容纳的数据元素的最大数量。这一容量在缓冲区创建时被设定,

2017-06-12 00:14:01 214

原创 Java NIOAIO了解

一、阻塞和非阻塞阻塞和非阻塞是进程在访问数据的时候,数据内是否准备就绪的一种处理方式,当数据没有准备的时候。阻塞:往往需要等到缓冲区中的数据准备好过后才处理其他的事情,否则一直等待在那里。非阻塞:当我们的进程访问我们的数据缓冲区的时候,数据没有准备好的时候,直接返回,不需要等待数据。数据有的时候,也直接返回。二、同步和异步同步和异步都是基于应用程序和操作系统处理IO时间所采用的方式,比如同步应用程序

2017-06-01 01:17:20 240

原创 Nutch简介

Nutch是基于Java的开源搜索引擎。Nutch有如下优点:简单,支持分布式爬虫。Nutch爬虫的设计着重两个方面: 存储过程爬虫过程Nutch存储主要使用数据文件,数据文件有三类: Web database,也叫WebDB,仅在爬虫中使用,用于存储爬虫抓取的网页之间的链接结构信息。WebDB存储了两种实体信息: Page 描述网页的特征信息,包括网页内的链接数目、网页的抓取时间、网

2017-05-03 16:45:09 1057

原创 宽度优先爬虫和带偏好的爬虫的简单实现

图的遍历分为宽度优先遍历和深度优先遍历两种方式,由于网络的无限性,爬虫采用深度优先遍历会导致陷入过深,故应采用宽度优先遍历,同时,还可以根据遍历网页的权重分配优先级,这就是带偏好的遍历。宽度优先遍历从一系列种子节点开始后,应将之后的子节点依次放入待访问队列,同时,应该保存一张已访问的表,遍历前应先查询是否访问过,从而避免重复访问。即可分为下列步骤: 1. 把解析出来的链接和已访问表中的链接进行比较

2017-04-12 16:17:46 348

原创 USACO | Greedy Gift Givers

题目链接 题意就是给定人员,每次从其中一个人拿出一定数值,平分给特定的几个人(无法整数平分的剩余部分则保留),经过N次这样的步骤后输出各自最后拥有的数值大小。下面是C++实现/*ID: imzheng1PROG: gift1LANG: C++*/#include<iostream>#include<fstream>#include<string>using namespace std

2017-04-11 15:25:29 311

原创 用Java抓取网页

URI与URLURI是通用资源标识符,由三部分组成 1. 访问资源命名机制 2. 存放资源的主机名 3. 资源本身的名称而URL是URI的子集,称为统一资源定位符,由三部分组成 1. 协议 2. 主机IP地址 3. 主机资源的具体地址,如目录与文件名爬虫最主要的处理对象就是URL。抓取网页的工具Java语言是为网络而生的语言,Java将网络资源看成一种文件,使对网络资源的访问呢与获取像对

2017-04-10 09:34:20 592

原创 hihoCoder | hiho一下145周 智力竞赛

题目链接 题目分析代码如下,给注释好了。 第一次提交,编译错误,与vs不同,hiho使用memset记得添加cstring,否则报错。又交了5次WA,才发现少打了一个=号。#include <iostream>#include <algorithm>#include <cstring>using namespace std;int const NUM = 1005;int const I

2017-04-09 02:24:01 538

原创 hihoCoder | hiho一下144周 机会渺茫

hiho一下144周题,题意是找出随机取出两个数刚好是n,m公因数的概率。思路是分别找出两个数所有因数,相乘得到取数情况,易得公因数个数。再调用求最大公因数函数,输出化简后的数字就行。map存放n的因数,m每次找到因数时到map去找是否已包含,以此确定公因数,将map理解为一个hashset即可。#include <iostream>#include <map>using namespace s

2017-04-02 01:51:24 474

原创 USACO | Your Ride Is Here

题目链接简单说一下题意,就是任给两个字符串,分别算出两个字符串中每个字母对应数字乘积,再各自模47,若取模后值相等,则返回GO,否则返回STAY。下面是C++实现/*ID: imzheng1PROG: rideLANG: C++*/#include <iostream>#include <fstream>#include <string>using namespace std;int

2017-04-02 00:35:27 350

原创 LintCode | 177. 把排序数组转换为高度最小的二叉搜索树

给一个排序数组(从小到大),将其转换为一棵高度最小的排序二叉树。 注意事项 There may exist multiple valid solutions, return any of them.先找出最中间的数,再分别找出左右两边子数组最中间的数,递归求解/*** Definition of TreeNode:* public class TreeNode { * p

2017-03-31 23:58:42 207

原创 LeetCode | 383. Ransom Note

Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; oth

2017-03-28 22:49:35 234

原创 LintCode | 55. 比较字符串

比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是大写字母 题目链接public class Solution { /** * @param A : A string includes Upper Case letters * @param B : A string includes Upper Case letter * @

2017-03-28 22:18:13 642

原创 LeetCode | 453. Minimum Moves to Equal Array Elements

Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1. Example: Input: [1,2,

2017-03-26 11:44:06 235

原创 LintCode | 93. 平衡二叉树

深度复制一个二叉树。 给定一个二叉树,返回一个他的 克隆品 。/*** Definition of TreeNode:* public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.

2017-03-26 10:45:39 212

原创 LeetCode | 455. Assign Cookies

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cook

2017-03-24 19:49:51 187

原创 LintCode | 111. 爬楼梯

假设你正在爬楼梯,需要n步你才能到达顶部。但每次你只能爬一步或者两步,你能有多少种不同的方法爬到楼顶部? 题目链接DP基础题,不多说了。取模可以减少空间浪费。public class Solution { /** * @param n: An integer * @return: An integer */ public int climbSta

2017-03-24 19:26:48 388

原创 LintCode | 66. 二叉树的前序遍历

给出一棵二叉树,返回其节点值的前序遍历。 题目链接/*** Definition of TreeNode:* public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = v

2017-03-23 15:23:58 606

原创 LeetCode | 167. Two Sum II - Input array is sorted

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbe

2017-03-23 15:23:09 170

原创 LeetCode | 506. Relative Ranks

Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: “Gold Medal”, “Silver Medal” and “Bronze Medal”. Example 1: I

2017-03-22 21:32:05 199

原创 LintCode | 68. 二叉树的后序遍历

给出一棵二叉树,返回其节点值的后序遍历。 题目链接/*** Definition of TreeNode:* public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = v

2017-03-22 18:34:10 320

原创 LeetCode | 530. Minimum Absolute Difference in BST

Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes. 题目链接最容易想到的方法,由于是BST,直接中序遍历后即可得到排序后的list,再把排序后的list两两比较找出相差最小的值即可。/*** Def

2017-03-21 18:31:32 275

原创 LintCode | 480. 二叉树的所有路径

给一棵二叉树,找出从根节点到叶子节点的所有路径。 题目链接可参考376题一起做/*** Definition of TreeNode:* public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { *

2017-03-21 13:42:32 285

原创 LeetCode | 448. Find All Numbers Disappeared in an Array【经典题】

Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this array.

2017-03-20 20:41:43 153

原创 LintCode | 376. 二叉树的路径和

给定一个二叉树,找出所有路径中各节点相加总和等于给定 目标值 的路径。 一个有效的路径,指的是从根节点到叶节点的路径。题目不难,关键在于想清楚递归怎么判断。/*** Definition of TreeNode:* public class TreeNode { * public int val; * public TreeNode left, right; *

2017-03-20 19:23:37 584

原创 LeetCode | 492. Construct the Rectangle

For a web developer, it is very important to know how to design a web page’s size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L

2017-03-19 22:27:39 168

原创 LintCode | 69. 二叉树的层次遍历

给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问)/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val

2017-03-19 19:43:34 608

原创 LeetCode | 520. Detect Capital

Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cases holds: All letters i

2017-03-16 19:38:05 230

原创 LeetCode | 496. Next Greater Element I

You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corresponding places of nums2.

2017-03-15 19:52:58 163

原创 LintCode | 93. 平衡二叉树

给定一个二叉树,确定它是高度平衡的。对于这个问题,一棵高度平衡的二叉树的定义是:一棵二叉树中每个节点的两个子树的深度相差不会超过1。 题目链接递归解决,递归函数每次返回两棵子数的深度,并进行比较,相等或相差仅为1则返回最大值,否则返回-1。用-1表示该子树已不平衡。/** * Definition of TreeNode: * public class TreeNode { *

2017-03-15 19:25:26 527

原创 LeetCode | 485. Max Consecutive Ones

Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are con

2017-03-14 21:04:09 295

原创 LintCode | 167. 链表求和

你有两个用链表代表的整数,其中每个节点包含一个数字。数字存储按照在原来整数中相反的顺序,使得第一个数字位于链表的开头。写出一个函数将两个整数相加,用链表形式返回和。/*** Definition for singly-linked list.* public class ListNode { * int val; * ListNode next; * ListNo

2017-03-14 20:15:12 593

原创 LeetCode | 463. Island Perimeter

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely s

2017-03-13 20:43:48 248

原创 LintCode | 569. Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 样例 Given num = 38. The process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit,

2017-03-13 20:04:27 243

原创 LintCode | 408. 二进制求和

给定两个二进制字符串,返回他们的和(用二进制表示)。比较蠢的办法public class Solution { public String addBinary(String a, String b) { //分别用 max min 指向长度最长 最短字符串 String max, min; if(a.length() > b.length())

2017-03-12 21:23:01 302

原创 LeetCode | 412. Fizz Buzz

Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.

2017-03-08 19:47:11 296

空空如也

空空如也

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

TA关注的人

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