- 博客(25)
- 收藏
- 关注
转载 数组问题
给定一个数组和数组的一个索引,把小于该索引表示数值的元素移到左边,等于该元素的放在一起,大于该元素的移到数组右边。解体思路:索引为[0, smaller - 1]为小于pivot的值 [smaller, equal - 1]为等于pivot的值 [equal, larger]为未分类元素的值 [larger+1, |A| - 1]...
2015-05-25 19:45:00
162
转载 【tools】vim删除命令
x 删除当前光标下的字符dw 删除光标之后的单词剩余部分。d$ 删除光标之后的该行剩余部分。dd 删除当前行。c 功能和d相同,区别在于完成删除操作后进入INSERT MODEcc 也是删除当前行,然后进入INSERT MODE删除每行第一个字符:%s/^.//gu 撤销上一步的操作Ctrl+r 恢复...
2015-04-24 15:17:00
170
转载 【hihocoder】1014 : Trie树
描述小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能对于每一个我给出的字符串,都在这个词典里面找到以这个字符串开头的所有单词呢?”身经百战的小Ho答道:“怎么会不能呢!你每给我一个字符串,我就依次遍历词典里的所有...
2015-04-19 21:04:00
149
转载 【编程之美】题目2 : 回文字符序列
source:http://hihocoder.com/contest/msbop2015qual/problem/2描述给定字符串,求它的回文子序列个数。回文子序列反转字符顺序后仍然与原序列相同。例如字符串aba中,回文子序列为"a", "a", "aa", "b", "aba",共5个。内容相同位置不同的子序列算不同的子序列。输入第一行一个整数T,表示数据组数。之...
2015-04-19 20:08:00
147
转载 【编程之美】题目3:基站选址
source:http://hihocoder.com/contest/msbop2015qual/problem/3描述需要在一个N × M的网格中建立一个通讯基站,通讯基站仅必须建立在格点上。网格中有A个用户,每个用户的通讯代价是用户到基站欧几里得距离的平方。网格中还有B个通讯公司,维护基站的代价是基站到最近的一个通讯公司的路程(路程定义为曼哈顿距离)。在网格...
2015-04-19 19:57:00
401
转载 【编程之美】题目1 : 2月29日
source:http://hihocoder.com/contest/msbop2015qual/problem/1描述给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期)。只有闰年有2月29日,满足以下一个条件的年份为闰年:1. 年份能被4整除但不能被100整除2. 年份能被400整除输入第一行为一个整数T,表示数据组数。之后每组数据...
2015-04-19 19:51:00
127
转载 【leetcode】 Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as...
2015-04-16 22:24:00
107
转载 【leetcode】 Merge Intervals
Merge IntervalsGiven a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].解题思路: 根据start对区间进行排序,...
2015-04-06 16:50:00
104
转载 【python】UnicodeEncodeError: 'ascii' codec can't encode/decode characters
解决方案在文件头插入# encoding=utf8 import sys reload(sys) sys.setdefaultencoding('utf8') 转载于:https://www.cnblogs.com/zxy1992/p/4396091.html
2015-04-06 16:02:00
97
转载 【hihocoder】 Magic Box
题目1 : Magic Box时间限制:10000ms单点时限:1000ms内存限制:256MB描述The circus clown Sunny has a magic box. When the circus is performing, Sunny puts some balls into the box one by one. The...
2015-04-04 16:54:00
120
转载 【hihocoder】二分·归并排序之逆序对
描述在上一回、上上回以及上上上回里我们知道Nettle在玩《艦これ》。经过了一番苦战之后,Nettle又获得了的很多很多的船。这一天Nettle在检查自己的舰队列表:我们可以看到,船默认排序是以等级为参数。但实际上一个船的火力值和等级的关系并不大,所以会存在A船比B船等级高,但是A船火力却低于B船这样的情况。比如上图中77级的飞龙改二火力就小于55级的夕立改二。现在Nettle将...
2015-04-04 16:07:00
114
转载 【leetcode】 Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe ...
2015-04-02 14:34:00
122
转载 【leetcode】Path Sum2
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum = 22, 5 ...
2015-04-02 14:27:00
101
转载 【leetcode】Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree ands...
2015-04-02 14:22:00
95
转载 【leetcode】Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, ...
2015-04-02 11:36:00
100
转载 windows类似grep的命令——findstr
使用Chrome发现访问google总是向香港那边跳转,估计配置文件中google网站映射的地址是www.google.com.hk,便想着改配置文件,但不知道配置文件在哪儿。找到了Chrome浏览器默认的目录C:\Users\zxy\AppData\Local\Google\Chrome,还是无处下手,Linux下的个grep命令用于查找字符串,windows也应该提供一些操作方法啊,...
2015-03-27 19:49:00
300
转载 【leetcode】pow(x, n)
Implement pow(x,n).二分法,注意n为负数的处理。class Solution {public: double power(double x, int n) { if (n == 0) return 1; double v = power(x, ...
2015-03-24 13:14:00
109
转载 区间合并
总时间限制:1000ms内存限制:65536kB描述给定 n 个闭区间 [ai; bi],其中i=1,2,...,n。任意两个相邻或相交的闭区间可以合并为一个闭区间。例如,[1;2] 和 [2;3] 可以合并为 [1;3],[1;3] 和 [2;4] 可以合并为 [1;4],但是[1;2] 和 [3;4] 不可以合并。我们的任务是判断这些区间是否可以最终合并为一个闭区间,如...
2015-03-24 13:07:00
388
转载 【leetcode】 Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine ...
2015-02-07 19:47:00
85
转载 【leetcode】Spiral Matrix II
Spiral Matrix IIGiven an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example,Given n = 3,You should return the following matrix:[ ...
2015-02-07 16:34:00
91
转载 【leetcode】 Spiral Matrix
Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, ...
2015-02-07 15:45:00
89
转载 POJ 2533 Longest Ordered Subsequence
DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK), where 1 ...
2013-12-09 19:40:00
101
转载 数组指针与指针数组
一、数组指针是指向数组的一个指针,例如int (*p)[4];,表示的是p指向拥有4个元素的数组的指针,p是指向一维数组的首地址。int a[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};int (*p)[4];(*p)[0]保存的元素1,p+1表示指针位置下移一行,*(p+2)+3表示的是第二行第三列元素的地址,即&a[2][...
2013-12-01 12:20:00
95
转载 函数指针小结
函数指针指指向函数的指针,强调指针,函数名是内存中的起始地址。格式为:int(*fun)(int,int)。指针函数强调函数,指返回值是指针类型的函数。指针函数常见,不再具体说明。格式为:int*fun(int,int);#include <stdio.h> #define N 10 /*...
2013-12-01 12:15:00
78
转载 给一手扑克牌分类
最近看了《C语言程序设计程序 现代方法》,里面一个问题挺有意思的。原本自己写了一个,但结构混乱,示例程序条理清晰,全局变量用的挺好,故又按照书上的程序敲了一遍。每次读取一手五张牌,然后根据下列类别把手中的牌分类(列出的顺序依次是从最好类别到最坏类别):Straightflush:同花顺的牌(即顺序相连又都是同花色)Four-of-a-kind:四张相同的牌(四张牌级...
2013-11-27 18:44:00
530
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅