05 2014 档案

LeetCode --- Valid Palindrome
摘要:题目链接判断字符串是否为回文串。附上代码: 1 class Solution { 2 public: 3 bool isPalindrome(string s) { 4 if (s.empty()) return true; // consider empty string ... 阅读全文

posted @ 2014-05-29 21:54 Stomach_ache 阅读(130) 评论(0) 推荐(0) 编辑

LeetCode --- Longest Consecutive Sequence
摘要:题目链接对unordered_set和set的内部实现还不了解,只知道前者是hash实现的,后者是用R-B-Tree实现。有时间需要读下源码。附上代码: 1 class Solution { 2 public: 3 int longestConsecutive(vector &num) { ... 阅读全文

posted @ 2014-05-29 12:28 Stomach_ache 阅读(102) 评论(0) 推荐(0) 编辑

LeetCode --- Insertion Sort List
摘要:题目链接实现链表的插入排序附上代码: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(i... 阅读全文

posted @ 2014-05-29 01:24 Stomach_ache 阅读(123) 评论(0) 推荐(0) 编辑

数据库lib7第2, 3题(创建索引和触发器)
摘要:2. 分别为上述建立的表格建立适当的索引,请描述建立索引的过程(可以截图或者写SQL)。其中,要求对SPJ标中的SNo, PNo字段各建立一个索引,为(PNo, JNo)的组合建立一个索引。请问,SNo和PNo上的索引是聚集索引还是非聚集索引?为什么?附上代码:1 create index SNo_... 阅读全文

posted @ 2014-05-27 13:40 Stomach_ache 阅读(210) 评论(0) 推荐(0) 编辑

LeetCode --- Reverse Integer
摘要:题目链接从代码的健壮性考虑, 应该顾及到把数字翻转后发生溢出的情况,但是此题中并没有这种测试数据。附上代码: 1 class Solution { 2 public: 3 int reverse(int x) { 4 int tmp = abs(x); 5 i... 阅读全文

posted @ 2014-05-27 09:59 Stomach_ache 阅读(96) 评论(0) 推荐(0) 编辑

LeetCode --- Add Two Numbers
摘要:题目链接说来算是个基础题目,可是还是各种CE,各种WA,基础还是不扎实。附上代码: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *ne... 阅读全文

posted @ 2014-05-27 09:29 Stomach_ache 阅读(133) 评论(0) 推荐(0) 编辑

LeetCode --- Climbing Stairs
摘要:题目链接简单递推附上代码: 1 class Solution { 2 public: 3 int climbStairs(int n) { 4 int f0 = 1, f1 = 1, f2 = 1; 5 for (int i = 2; i <= n; i++)... 阅读全文

posted @ 2014-05-27 08:28 Stomach_ache 阅读(150) 评论(0) 推荐(0) 编辑

LeetCode --- Best Time to Buy and Sell Stock II
摘要:题目链接附上代码: 1 class Solution { 2 public: 3 int maxProfit(vector &prices) { 4 unsigned int len = prices.size(); 5 if (len == 0) retur... 阅读全文

posted @ 2014-05-26 23:50 Stomach_ache 阅读(107) 评论(0) 推荐(0) 编辑

LeedCode --- Best Time to Buy and Sell Stock
摘要:题目链接题意: find the maximum positive difference between the price on the ith day and the jth day附上代码: 1 class Solution { 2 public: 3 int maxProfit(ve... 阅读全文

posted @ 2014-05-26 17:19 Stomach_ache 阅读(154) 评论(0) 推荐(0) 编辑

git命令总结
摘要:学会这些命令,你就可以熟练的使用Git工具了,什么?想精通,那是不可能的。基本上,Git就是以下面的命令顺序学习的。文中笔记是从廖雪峰老师的Git教程中总结出来的,方面查阅命令。详细原理请看Git教程。1、基础git config --global user.name "Your Name"设置你的... 阅读全文

posted @ 2014-05-22 18:12 Stomach_ache 阅读(222) 评论(0) 推荐(1) 编辑

LeetCode --- Jump Game II
摘要:题目链接题目描述:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents ... 阅读全文

posted @ 2014-05-21 13:34 Stomach_ache 阅读(105) 评论(0) 推荐(0) 编辑

Hdu 4497
摘要:题目链接已知 gcd(x, y, z) = G, lcm(x, y, z) = L, 求有多少种组合(x, y, z)可以满足条件。G, L都在32位int范围内。思路: 素数分解 + 容斥L : p1^t1 * p2^t2 ... * pi^tiG: q1^s1 * q2^s2... * qi^s... 阅读全文

posted @ 2014-05-20 23:53 Stomach_ache 阅读(272) 评论(0) 推荐(0) 编辑

数据库lib7第4题创建存储过程
摘要:1. 传入2个字符串变量,其中,每个字符串是用分号(;)分隔的字串形式, 比如str1=’ab12;ab;cccc;tty’, str2=’1;6sf;8fffff;dd’, 注意,字符串是用户输入的,不能固定值、长度、和分号个数。2. 执行完毕存储过程后,要求根据分号提取字符串的字... 阅读全文

posted @ 2014-05-20 14:35 Stomach_ache 阅读(275) 评论(0) 推荐(0) 编辑

Hdu 4496
摘要:题目链接并查集简单题,赛前复习 :.....附上代码: 1 /************************************************************************* 2 > File Name: 4496.cpp 3 > Author: S... 阅读全文

posted @ 2014-05-20 00:38 Stomach_ache 阅读(184) 评论(0) 推荐(0) 编辑

Hdu 4493
摘要:题目链接注意四舍五入,保留到小数点后两位(如果存在的话)。附上代码: 1 /************************************************************************* 2 > File Name: 4493.cpp 3 > Au... 阅读全文

posted @ 2014-05-19 23:37 Stomach_ache 阅读(420) 评论(0) 推荐(0) 编辑

Leetcode ---- Swap Nodes in Pairs
摘要:题目链接题意:给出单链表头指针,要求交换链表中每一对相邻的结点.注意:不可以改变链表中结点的值,只可以使用常量空间.附上代码: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val;... 阅读全文

posted @ 2014-05-19 18:24 Stomach_ache 阅读(133) 评论(0) 推荐(0) 编辑

LeetCode --- Linked List Cycle II
摘要:题目链接题意: 给出单链表,判断是否存在环,如果存在要求输出环开始的结点.思路及证明:It is a famous known problem Hare and Tortoise.Length of head to cycle started node: xLength of the cycle: ... 阅读全文

posted @ 2014-05-18 11:51 Stomach_ache 阅读(106) 评论(0) 推荐(0) 编辑

Python sorted
摘要:sorted函数:iterable:是可迭代类型;cmp:用于比较的函数,比较什么由key决定,有默认值,迭代集合中的一项;key:用列表元素的某个属性和函数进行作为关键字,有默认值,迭代集合中的一项;reverse:排序规则. reverse = True 或者 reverse = False,有... 阅读全文

posted @ 2014-05-17 19:29 Stomach_ache 阅读(229) 评论(0) 推荐(0) 编辑

每天一个linux命令(2): nl命令
摘要:0.学习时间 2014-05-161.命令格式 nl [参数] 文件名 (文件名也缺省的情况下, 从标准输入中读入)2.命令参数 -b t 空行不加行号(默认) -b a 空行也加行号(类似于cat -n) -n ln 设置行号显示左对齐 -n rn 设置行号显示右对齐(默认) ... 阅读全文

posted @ 2014-05-16 21:38 Stomach_ache 阅读(167) 评论(0) 推荐(0) 编辑

Codeforces 432C
摘要:题目链接题意: 给出一个长度为n(n File Name: C.cpp 3 > Author: Stomach_ache 4 > Mail: sudaweitong@gmail.com 5 > Created Time: 2014年05月15日 星期四 23时51分15秒... 阅读全文

posted @ 2014-05-16 19:15 Stomach_ache 阅读(394) 评论(0) 推荐(1) 编辑

LeetCode -- Linked List Cycle
摘要:题目链接题意: 给出单链表, 判断是否存在环.方法就是大步小步...附上代码: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next... 阅读全文

posted @ 2014-05-15 22:54 Stomach_ache 阅读(107) 评论(0) 推荐(0) 编辑

每天一个linux命令(1): which命令
摘要:0.学习时间: 2014-05-15which命令用来在PATH指定的路径中查找特定的文件, 并返回第一个找到的结果.1. 命令格式: which 文件名2.命令功能 一般使用which命令来查看某个系统命令(可执行文件)是否存在, 以及该命令所在的目录.3.命令参数 -n 指定文件名长度... 阅读全文

posted @ 2014-05-15 21:10 Stomach_ache 阅读(195) 评论(0) 推荐(0) 编辑

Hdu 1867 KMP
摘要:题目链接题目意思: 给出两个字符串a, b, 求最长的公共字串c, c是a的后缀,也是b的前缀. 本题没有具体说明哪个字符串是文本串和匹配串, 所以都要考虑思路: 查找的时候, 当文本串结束的时候, 返回匹配串的位1 /****************************************... 阅读全文

posted @ 2014-05-15 12:42 Stomach_ache 阅读(143) 评论(0) 推荐(0) 编辑

c++11的新特性
摘要:好奇心来源于下面的一段代码, 一个是unordered_map, 这是c++11新加的container. 另外还有unordered_set, unordered_multimap, unordered_multiset.另外在for循环中, 可以使用下列形式:1 for (auto &eleme... 阅读全文

posted @ 2014-05-15 10:21 Stomach_ache 阅读(120) 评论(0) 推荐(0) 编辑

Hdu 1496 hash
摘要:题目链接对于方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0 ( -50 File Name: 1496.cpp 3 > Author: Stomach_ache 4 > Mail: sudaweitong@gmail.com 5 > Cre... 阅读全文

posted @ 2014-05-14 18:34 Stomach_ache 阅读(121) 评论(0) 推荐(0) 编辑

python中defaultdict类
摘要:回宿舍前翻翻Codeforces的时候发现了一个有趣的代码..其实是我没这么用过 :D这是一份417B的代码 1 import sys 2 from collections import defaultdict 3 4 n = int(sys.stdin.readline()) 5 d = def... 阅读全文

posted @ 2014-05-13 23:18 Stomach_ache 阅读(183) 评论(0) 推荐(0) 编辑

Hdu 2522 hash
摘要:题目链接题意:输入整数n (1 1, 被除数初始left = 1, 做除法时, 如果left File Name: 2522.cpp 3 > Author: Stomach_ache 4 > Mail: sudaweitong@gmail.com 5 > Created ... 阅读全文

posted @ 2014-05-13 22:57 Stomach_ache 阅读(136) 评论(0) 推荐(0) 编辑

Hdu 1800 字符串hash
摘要:题目链接题意: 给出n(n File Name: 1800.cpp 3 > Author: Stomach_ache 4 > Mail: sudaweitong@gmail.com 5 > Created Time: 2014年05月13日 星期二 20时12分31秒 6 ... 阅读全文

posted @ 2014-05-13 21:35 Stomach_ache 阅读(209) 评论(0) 推荐(0) 编辑

为什么printf()用%f输出double型,而scanf却用%lf呢?
摘要:之前没有注意过这个问题, 转自:http://book.51cto.com/art/200901/106880.htm问:有人告诉我不能在printf中使用%lf。为什么printf()用%f输出double型,而scanf却用%lf呢?答:printf的%f说明符的确既可以输出float型又可以输... 阅读全文

posted @ 2014-05-13 20:49 Stomach_ache 阅读(953) 评论(0) 推荐(0) 编辑

BKDRHash算法的初步了解
摘要:字符串hash最高效的算法, 搜了一下, 原理是:字符串的字符集只有128个字符,所以把一个字符串当成128或更高进制的数字来看,当然是唯一的这里unsigned不需要考虑溢出的问题, 不过周神说:碰撞率很小是因为n阶多项式最多n个根. 也是有道理的.最后 hash & 0x7FFFFFFF 只是为... 阅读全文

posted @ 2014-05-13 20:08 Stomach_ache 阅读(2187) 评论(0) 推荐(0) 编辑

LeetCode---Remove Nth Node From End of List
摘要:题目链接题意: 给出单链表头指针head和整数n, 要求删除链表的倒数第n个结点, 这里n保证是合法的输入.我的思路....其实我没大明白题目建议的one pass是什么意思, 可能就是遍历一遍链表的, 不过我还是秉着能A掉就万岁的心态...我还是首先记录了链表的长度, 然后删除第len - n +... 阅读全文

posted @ 2014-05-13 19:28 Stomach_ache 阅读(244) 评论(0) 推荐(0) 编辑

字符串Hash算法比较
摘要:基本概念所谓完美哈希函数,就是指没有冲突的哈希函数,即对任意的 key1 != key2 有h(key1) != h(key2)。设定义域为X,值域为Y, n=|X|,m=|Y|,那么肯定有m>=n,如果对于不同的key1,key2属于X,有h(key1)!=h(key2),那么称h为完美哈希函数,... 阅读全文

posted @ 2014-05-13 09:39 Stomach_ache 阅读(3462) 评论(0) 推荐(0) 编辑

LeetCode---Remove Duplicates from Sorted List II
摘要:题目链接题意: 给出单链表的head指针, 要求去除链表中所有出现重复的元素, 如1->2->3->3->4->4->5, 返回1->2->5这题纠结了有两天, 重要的是把思路想清楚然后就可以痛苦的A掉, 不然老是会绕来绕去...我的大体思路是这样的: 使用三个指针 pre保存链表中前一个没有出现重... 阅读全文

posted @ 2014-05-12 22:04 Stomach_ache 阅读(120) 评论(0) 推荐(0) 编辑

hackerrank---Sets - Symmetric Difference
摘要:题目链接集合操作附上代码:1 M = int(input())2 m = set(map(int, raw_input().strip().split()))3 N = int(input())4 n = set(map(int, raw_input().strip().split()))5 tmp... 阅读全文

posted @ 2014-05-11 17:17 Stomach_ache 阅读(143) 评论(0) 推荐(0) 编辑

hackerrank---Find a string
摘要:题目链接在字符串a中查找字符串b出现的次数...貌似不可以用a.count()附上代码:1 a = raw_input().strip()2 b = raw_input().strip()3 cnt = 0;4 for i in xrange(len(a)):5 cnt += 1 if a.... 阅读全文

posted @ 2014-05-11 16:53 Stomach_ache 阅读(167) 评论(0) 推荐(0) 编辑

hackerrank---List Comprehensions
摘要:题目链接刷刷Python基本功...列表解析附上代码:1 x = int(input())2 y = int(input())3 z = int(input())4 n = int(input())5 print [[i, j, k] for i in xrange(x+1) for j in xr... 阅读全文

posted @ 2014-05-11 16:29 Stomach_ache 阅读(189) 评论(0) 推荐(0) 编辑

LeetCode --- Plus One
摘要:题目链接题意:给出一个以数组形式表示的数, 求该数加1后的结果,同样以数组形式返回。附上代码: 1 class Solution { 2 public: 3 vector plusOne(vector &digits) { 4 unsigned int len = digit... 阅读全文

posted @ 2014-05-10 11:14 Stomach_ache 阅读(146) 评论(0) 推荐(0) 编辑

Vim学习与总结
摘要:1. :w 后面可以加文件名2. 使用hjkl 来移动光标,当然你也可以使用箭头。j就是向下的箭头,k是向上,h向左, l向右3. :help → 显示相关命令的帮助。你也可以就输入:help而不跟命令。(退出帮助需要输入:q)4. cw替换从光标开始到一个单词结束的字符, cc替换光标所在... 阅读全文

posted @ 2014-05-09 17:03 Stomach_ache 阅读(178) 评论(0) 推荐(0) 编辑

LeetCode --- Pascal's Triangle II
摘要:题目链接题意:在杨辉三角中,给定整数k,输出第k行。附上代码: 1 class Solution { 2 public: 3 vector getRow(int rowIndex) { 4 vector ans(rowIndex+1); 5 // 注意第0行为... 阅读全文

posted @ 2014-05-09 12:24 Stomach_ache 阅读(111) 评论(0) 推荐(0) 编辑

LeetCode --- Gray Code
摘要:题目链接一道关于格雷码的题目, 给出n, 输出n位的格雷码。 关于格雷码的详细说明和计算方法请右键:Wiki附上代码: 1 class Solution { 2 public: 3 vector grayCode(int n) { 4 vector ans(1); 5 ... 阅读全文

posted @ 2014-05-08 18:50 Stomach_ache 阅读(121) 评论(0) 推荐(0) 编辑

LeetCode --- Two Sum
摘要:题目链接附上代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 class Solution { 7 public: 8 vector twoSum(vector &numbers, int target) ... 阅读全文

posted @ 2014-05-08 11:33 Stomach_ache 阅读(80) 评论(0) 推荐(0) 编辑

LeetCode --- Pascal's Triangle
摘要:题目链接杨辉三角附上代码: 1 class Solution { 2 public: 3 vector > generate(int numRows) { 4 vector > ans(numRows); 5 for (int i = 0; i 0) {11... 阅读全文

posted @ 2014-05-08 11:28 Stomach_ache 阅读(86) 评论(0) 推荐(0) 编辑

LeetCode -- Remove Duplicates from Sorted List
摘要:题目链接简单题,就是从单链表中删除重复元素。附上代码: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * L... 阅读全文

posted @ 2014-05-08 10:44 Stomach_ache 阅读(108) 评论(0) 推荐(0) 编辑

LeetCode --Binary Tree Level Order Traversal II
摘要:题目链接在这题各种RE和WA。 方法上就是BFS, 还是基础不扎实的原因,很明显的一点就是这里使用二维vector, 开始的时候我竟然没有给ans分配空间,然后直接push_back, 导致RE到死。这点是必须引起注意的!附上代码: 1 /** 2 * Definition for binary ... 阅读全文

posted @ 2014-05-08 10:28 Stomach_ache 阅读(189) 评论(0) 推荐(0) 编辑

shell脚本学习
摘要:1. 关于自定义函数比如定义了一个函数名为hello的函数:1 function hello{2 3 echo "Hello World!"4 5 return 16 7 }1 #调用函数2 hello3 4 #保存函数返回值5 a=$?若将函数写在单独的文件中,可以用下面的方式来调用,假设... 阅读全文

posted @ 2014-05-05 19:43 Stomach_ache 阅读(241) 评论(0) 推荐(0) 编辑

shell脚本练习题(更新中...)
摘要:练习题(这里贴的是自己写的代码, 网上给的题目代码我会附加在最下面)1.编写shell脚本,计算1-100的和; 1 #!/bin/bash 2 #caculate the sum of numbers from 1 to 100 3 4 sum=0 5 for i in `seq 1 100`;... 阅读全文

posted @ 2014-05-05 17:53 Stomach_ache 阅读(1166) 评论(0) 推荐(0) 编辑

SQL Server 记录(更新中...)
摘要:sys.databases显示所有数据库信息sys.tables显示当前数据库所有的表的信息Go向 SQL Server 实用工具发出一批 Transact-SQL 语句已结束的信号,Go本身不是T-SQL语句sq_addrole 等等SQL Server系统存储过程以字符 sp_ 开头。EXEC或... 阅读全文

posted @ 2014-05-04 22:44 Stomach_ache 阅读(259) 评论(0) 推荐(0) 编辑

LeetCode---Gas Station
摘要:明知道明早要考试,可还是忍不住打开电脑想水一题。不过还是在这题上WA了好几次....看见自己有多渣!有个道理发现了很久,直到今天才意识到它的严重性,反复的做题只能让你不断的巩固已有的知识,而对于新知识的探索是少只又少,所以必须要通过多读书来获取新的知识,这样才能够扩充知识面。而之前的我就是忽略了读书... 阅读全文

posted @ 2014-05-03 18:30 Stomach_ache 阅读(162) 评论(0) 推荐(0) 编辑

shell脚本批量杀死进程
摘要:使用Ubuntu系统时常会遇到机器卡死的情况(人生最大的痛苦),所有的键都没有用,只好强制关机,我似乎对此已经'乐此不疲了'。看到又神牛说: 可以在tty里面把相关的进程杀死,之后就正常。(到目前我还没有试过,好奇怪,自从写了这个脚本就再没有遇到死机的情况)我用的一个脚本就是: 1 ########... 阅读全文

posted @ 2014-05-03 15:09 Stomach_ache 阅读(1025) 评论(0) 推荐(0) 编辑

LeetCode---Merge Intervals
摘要:题目链接区间合并,贪心,需要注意边界情况,LeetCode的数据还是比较好的,这样才能写出健壮的程序。附上代码: 1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * in... 阅读全文

posted @ 2014-05-02 21:39 Stomach_ache 阅读(143) 评论(0) 推荐(0) 编辑

LeetCode---Triangle
摘要:题目链接很简单的递推,但是写代码的过程中,犯了一个严重的错误,就是我用unsigned int型变量>= 0 作为循环条件(而且是降序)的时候,出现了问题。附上代码: 1 class Solution { 2 public: 3 int minimumTotal(vector > &tria... 阅读全文

posted @ 2014-05-02 21:03 Stomach_ache 阅读(129) 评论(0) 推荐(0) 编辑

Hdu 4810
摘要:2014-05-0215:53:50题目连接2013年南京现场赛的题目,现场的时候,排在我们前面的队伍基本都过了这题,我们后面的队伍也有不少过了这题,唯独我们没有。。后来是Qingyu Shao想到了思路,然后就让他来敲,我记得当时是C(n,k)打表的时候出现了问题,好弱。。于是乎就开始吃东西了。回... 阅读全文

posted @ 2014-05-02 16:45 Stomach_ache 阅读(410) 评论(0) 推荐(0) 编辑

Codeforces 425B
摘要:点击打开题目链接 题意:给定一个n×m的0,1矩阵,做多可以对矩阵做k次变换,每次变换只可以将矩阵的某一个元素由0变成1,或从1变成0。求最小的变换次数使得得到的矩阵满足:每一个连通块都是一个“实心”矩形。要想清楚的就是最终的矩阵一定是这样的: 010...1 0 1 ...0 1 0 ... 这样... 阅读全文

posted @ 2014-05-01 10:04 Stomach_ache 阅读(279) 评论(2) 推荐(0) 编辑

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示