自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 sqlite源码剖析(一)

首先,我看完整个目录结构之后,我打算从sqlite的数据结构开始看起。 hash.h中定义了两个数据结构,Hash类包含以下成员struct Hash { char keyClass; /* 指示该hash是针对哪种基本类型而设置的,其设定4种 SQLITE_HASH_INT, _POINTER, _STRING, _BINARY */ char copyKey;

2017-04-06 11:03:44 3563

原创 c++bug小结(一)

昨天打codeforces,碰到两个bug,在此总结。用一元二次方程求解公式的精度问题1、在这里用一元二次方程求解公式之后,由于数据较大极有可能造成精度不高导致转化int类型之后与实际结果差1或着差2。 如公式x*x+x-c>=0,求出满足公式的最小整数x。 这里用一元二次方程求解,由于精度的问题,导致无法得到正确结果。此时将公式转化一下 x*x+x > =c, 假设x*x+x =c, 则

2017-03-17 12:14:54 714

转载 除法的取模运算

逆元: 若,b*b1 % c == 1 则,b1称为b模c的乘法逆元。 在ACM中,许多除法取模都要用到求逆元。 但是,逆元,为什么能给我们带来 ( a/b ) % c == ( a*b1 ) % c ???(当然a/b要整除)要知道,取模等式等价变形中,是没有除法的!!!而推导式,还是没有用除法的地方!!!我们用反证法证明: 若b*b1 % c == 1,则( a/b ) % c != ( a

2017-03-16 11:39:01 7174

转载 Epoll模型讲解

首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O操作的内核对象。不管是文件,还是套接字,还是管道,我们都可以把他们看作流。之后我们来讨论I/O的操作,通过read,我们可以从流中读入数据;通过write,我们可以往流写入数据。现在假定一个情形,我们需要从流中读数据,但是流中还没有数据,(典型的例子为,客户端要从socket读如数据,但是服务器还没有把数据传回来),这

2017-03-08 16:28:09 326

原创 正则表达式学习之一

这次爬取页面所用到的正则表达式 \s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\r\n\t\v] \S 匹配任何非空白字符,等价于 [^ \f\n\r\t\v]。 \w 匹配包括下划线的任何单词字符。等价于’[A-Za-z0-9_]’。 . 匹配除 “\n” 之外的任何单个字符 * 匹配前面的子表达式0次或1次 ? 匹配前面的子表达式零次或一次 + 匹配前

2017-03-08 16:17:15 669

原创 c++ Segmentation fault Warning

今天重新拾起c++ primer第五版复习了一下c++,看到第一章有一小处细节是之前没注意到的,特此补充。 “程序员常常在调试时添加打印语句。这类语句应该保证‘一直’刷新流。否则,如果程序崩溃,输出可能还留在缓冲区中,从而导致关于程序崩溃位置的错误推断“。 结合之前,我也经常使用过打印语句来调试代码,当出现段错误有时定位到程序错误位置,有时定位不到。才发现原来输出时是有一个与设备关联的缓冲区(b

2017-02-25 12:11:33 2433

原创 windows下使用Critical Section和Mutex实现线程同步实例

利用critical section 和 Mutex两种不同的线程同步的方法实现生产者消费者问题。生产者线程要能够对一个计数器进行增的操作,并且将其输出在控制台上,消费者线程能够对这个计数器进行减的操作,并将其输出在控制台上。两种线程都共享一个计数器。 其中增、减计数器的数我设置为1~6随机。测试两种方法的对比,用网上整理出的一张表如下1、使用CriticalSection 方法时,有一个临界区c

2016-06-02 14:49:09 1876

原创 c语言文件读写(fread,fprintf)

利用fread进行成块的文件读写 int fread(void *buf,int size,int count,FILE *stream) int fwrite(void *buf,int size,int count,FILE *stream) fread()函数从stream 指向的流文件读取count (字段数)个字段,每个字段为size(字段长度)个字符长,并把它们放

2016-05-25 15:38:25 3276

原创 多周期cpu设计(verilog)

由于之前设计过单周期,所以这里很多模块都是类似的 我是把所有数据选择器的模块都单独拿出来,这里主要有 32位的4选1数据选择器,5位的3选1选择器,32位的2选1选择器,对于pc+4、j和jal指令跳转的pc值都单独变成一个模块 上代码 写control unit时要根据不同的指令并且不同的状态发出不同的信号,其他信号为默认信号`timescale 1ns / 1ps/////////

2016-05-24 17:11:20 9632 1

原创 [codeforces]#350F. Restore a Number

F. Restore a Number time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard outputVasya decided to pass a very large intege

2016-05-06 14:05:08 1875

原创 [codeforces]#350E. Correct Bracket Sequence Editor

E. Correct Bracket Sequence Editor time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard outputRecently Polycarp sta

2016-05-06 13:25:09 1505

转载 MAC OSX10.10上搭建Apache,PHP,MySQL5.6.22,phpMyAdmin开发环境

apache的配置apache已经自带了,只需如下三个命令就可以了。 开启apache服务 sudo apachectl start 停止apache服务 sudo apachectl stop 重启服务 sudo apachectl restart 查看版本 httpd -v手动打开apache服务后,在浏览器输入localhost,将看到如下: 程序的根目录在/Libra

2016-05-02 16:13:00 706

原创 Linux下搭建SVN服务器

1、在进行svn服务器环境搭建之前首先用终端命令连接到服务器上。 在打开的终端页面,输入如下代码: ssh user@hostname 注:上边代码为固定格式,其中 user 为 linux 服务器的管理员名称 hostname 为 linux 服务器的IP 如: ssh haibor@1.2.3.4 如此就可以在mac一样远程登录管理你的linux服务

2016-04-24 09:47:15 621

原创 sicily1142(深搜加剪枝)

数据结构期末考试最后一道题,到现在才写出来哈。。 还是因为看了《编程之美》这本书一摞烙饼的排序问题之后才写的。 看完编程之美,才发现这道题原来这么坑。没有在多项式复杂度的解法。 然后我首先用编程之美类似的方法,导致time limit 《编程之美》书中的方法是先给定的upperbound为2*countn-1 当dfs之后有比upperbound小的再动态修改upperbound, 这样

2016-04-15 23:12:14 811

原创 c语言编写简单shell解释器

在windows开发环境下写一个简单shell解释器 1、输入一个exe可执行文件路径或命令后能启动该程序 2、输入txt文本文件的路径,能打开该文本文件中所指定的若干exe程序路径及命令打开程序首先要弄清shell解释器其实就是一个exe文件,在这个程序输入正确 命令,就有相应操作执行。接着启动程序其实就是在系统中创建进程, 用win32的api CreateaProcess()函数借口实

2016-04-14 14:45:59 5464

原创 codefoces_#346E - New Reform(并查集或dfs)

E. New Reform time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Berland has n cities connected by m bidirectional roads. No road connects a c

2016-04-12 17:15:04 618 2

原创 tcp-h数据&postgresql查询(数据库学习之二)

首先要了解好tcp-h各个表之间的关系,才能更好的查询我们想要的信息。 这里附上关系图的链接 理清所有表各自的联系,我就为大家翻译一遍吧(只能是大概意思) region 地区、范围的意思 nation 国家 supplier 供应商 customer顾客 orders 订单 lineitem 订单详情联系 part 产品 partsupp产品供应商 ship 运输Q1:Disp

2016-04-06 01:58:15 4129

原创 TPC-H数据导入postgresql教程

将tpc-h中生成数据载入postgresqlpostgresql & tpc-h(dbgen)1、做实验之前的配置a、首先在mac下安装postgresql 终端命令 brew install postgresql -v 若出现Error: Cannot write to /usr/local/Cellar 可以输入以下命令进行解决 sudo chown -R $USER /usr/l

2016-04-05 19:06:41 8858

原创 [codeforces]Goodbye_2015

F. New Year and Cleaningime limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Limak is a little polar bear. His parents told him to clean a house

2016-01-03 15:11:38 464

原创 [codeforces]Goodbye_2015

611E - New Year and Three Musketeerstime limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Do you know the story about the three musketeers? Anywa

2016-01-03 14:51:36 436

原创 [codeforces]Goodbye_2015

D - New Year and Ancient Prophecytime limit per test2.5 seconds memory limit per test512 megabytes inputstandard input outputstandard output Limak is a little polar bear. In the snow he found a scr

2016-01-03 14:12:25 366

原创 [codeforces]Goodbye_2015

C. New Year and Dominotime limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output They say “years are like dominoes, tumbling one after the other”. But

2016-01-03 13:41:48 918

原创 [codeforces]Goodbye_2015

B. New Year and Old Propertytime limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The year 2015 is almost over.Limak is a little polar bear. He h

2016-01-03 13:04:57 831

原创 codeforces#337 D. Vika and Segments

D. Vika and Segments(离散+扫描+线段数) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard out

2015-12-30 09:12:27 545

原创 LA 4513 Stammering Aliens

在这道题上学会了两种方法解决。一种是用哈希lcp法,另一种用后缀数组求解。 Dr. Ellie Arroway has established contact with an extraterrestrial civilization. However, all efforts to decode their messages have failed so far because, as luck

2015-11-08 01:18:58 490

原创 [leetcode#4]Longest Common Prefix

Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.找最长公共字符串。 思路:对字符串进行排序,先让s[0]与s[1]比较出公共前缀, 然后把公共前缀与每个字符串进行比较,得出最长公共前缀#include <cstring>#incl

2015-11-05 19:36:06 293

原创 [leetcode#6]ZigZag Conversion

[leetcode#6]ZigZag ConversionThe string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

2015-11-05 19:30:05 390

原创 codeforce #329div2 B. Anton and Lines

B. Anton and Linestime limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The teacher gave Anton a large geometry homework, but he didn’t do it (as

2015-11-05 11:32:52 465

原创 codeforces #328 C. The Big Race

C. The Big Race time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vector Willman and Array Bolt are the two most famous athletes of Byteforce

2015-11-01 12:03:31 464

原创 Trie字符串(Remember the Word, LA 3942)

Trie字符串(Remember the Word, LA 3942)给出一个由S个不同单词组成的字典和一个长字符串。把这个字符串分解成若干个单词的连接(单词可重复使用),有多少种方法?比如,有4个单词a、b、cd、ab,则abcd有两种分解方法:a+b+cd和ab+cd。 输入格式: 输入包含多组数据。每组数据第一行为小写字母组成的待分解字符串,长度不超过300000.第二行为单词

2015-11-01 00:03:00 376

原创 线段树(2)区间修改

线段树(2)区间修改快速序列操作I,给出一个n个元素的数组A1,A2,…,An,你的任务是设计一个数据结构支持一下两种操作 set(L, R, v): 把AL,AL+1,…,Ar的值全部修改为v(v>=0) Query(L, R):计算子序列AL,AL+1,…Ar的元素和、最小值和最大值。#include <cstdio>#include <algorithm>using namespace

2015-10-27 23:36:26 345

原创 [线段树点修改]动态最大连续和(Ray,Pass me the Dishes, LA 3938)

[线段树点修改]动态最大连续和(Ray,Pass me the Dishes, LA 3938)“Ray, Pass me the dishes!” After doing Ray a great favor to collect sticks for Ray, Poor Neal becomes very hungry. In return for Neal’s help, Ray makes

2015-10-27 23:29:53 591

原创 sicily1002. 放鸡蛋

sicily1002. 放鸡蛋Description 把M个同样的鸡蛋放在N个同样的篮子里,允许有的篮子空着不放,问共有多少种不同的放法?(用K表示)5,1,1和1,5,1 是同一种分法。请写一个程序来输出每一种放记鸡蛋的方法。Input 第一行是一个数字t,表示有t个测试用例接下来的t行每一行有两个数字M和N,中间用空格隔开,表示有M个鸡蛋和N个篮子Output 对于每一个用例,输出它

2015-10-26 16:26:20 1129

原创 sicily1000. 整数划分

Description 对于一个整数m,m > 0,它可以写成t个整数的和的形式(t>0):m = z1 + z2 + … + zt ,其中zi > 0且为整数(1≤i≤t)这t个整数就是整数m的一种划分。比如整数4有以下5种划分:43+12+22+1+11+1+1+1Input 第一行是一个整数n,代表有n个测试用例接下来的n行每一行是一个整数m,代表待划分的整数Output 对于每一个用

2015-10-26 16:14:14 818

原创 sicily1001 全排列(升序)

输入一个数字n,输出从1~n组成的数字的全排列,每个排列占一行,输出按照数值升序排列比如输入2,则输出是:1221又如输入3,则输出是:123132213231312321解题思路: 1、先将第一个数字分别与自己交换和其他数字交换,然后变成 n-1个数的全排列。 2、这样n-1个数字又可以看成第一个数字与自己和其他数字交换然后变成n-2个数的全排列,以此递归。 3、当交换到第m个数字,便进行输

2015-10-26 15:42:58 1197

原创 [leetcode]#78 Subsets

Given a set of distinct integers, nums, return all possible subsets.Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If

2015-10-21 11:12:15 572

原创 [leetcode]#160 Intersection of Two Linked Lists

Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘

2015-10-21 10:30:46 247

原创 范围最小值问题 (Range Minimum Query,RMQ)

include include include using namespace std; int d[1000][1000]; void RMQ_init(const vector& A) { int n = A.size(); for (int i = 0; i < n; i++) { d[i][0] = A[i]; } for (in

2015-10-19 11:52:45 802

原创 [leetcode] #155 Min Stack

[leetcode] #155 Min StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack. pop() – Removes the element on top of the

2015-10-14 10:21:21 493

原创 [leetcode] #141 Linked List Cycle

Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?用O(1)空间,判断单链表是否存在环解题思路:1、fast指针走两步, low指针走一步 2、循环后,若有环则存在fast指针追上low指针那一刻。至于为何走两步,而不走3步,4步

2015-10-14 10:02:29 461

空空如也

空空如也

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

TA关注的人

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