Divide Two Integers 用减法可能会超时,但可以用二分class Solution {public: int divide(int d1, int d2) {// d1/d2 if(d1==0) return 0; if(d2==1) return d1; if(d2==-1)
leetcode Reverse Nodes in k-Group 递归一下/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li
leetcode Remove Nth Node From End of List 题目说:Try to do this in one pass只用一遍遍历的话,p1先走n节点,p2再走,等到p1到达链表尾的时候p2正好在倒数第n+1个上面鸟/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode
leetcode 3Sum 3Sum Closest 4Sum 这几个题很典型也是国外一些知名公司经常会问到的题3Sum:排序,避免重复,时间复杂度O(n^2)class Solution {public: vector > threeSum(vector &num) { int len=num.size(); sort(num.begin(),num.begin()+len);
leetcode Longest Common Prefix 找出单词的最长公共前缀class Solution {public: string longestCommonPrefix(vector &strs) { int len=strs.size(); if(len==0) return ""; int length=strs[0].size(),j;
日志结构的合并树 The Log-Structured Merge-Tree 日志结构的合并树 The Log-Structured Merge-Tree近年来,随着互联网数据的日益增长,管理分布式数据需求的日益增加,Bigtable[1]等一系列NoSQL数据库开始涌现。Bigtable是一个分布式的结构化数据存储系统,它被设计用来处理海量数据,其在提供Tablet服务时使用内存中的memtable和GFS[2]中的SSTable来相互配合着来存储数据
poj 2431 Expedition 贪心+最大堆 当油量不够时从走过的油站中选最大加油量的#include#include#include#includeusing namespace std;#define MAX_N 10005struct node{ int dist,fuel;}t[MAX_N];bool cmp(const node &a,const node &b){ return a.dist<b.dis
poj 1664 放苹果 动态规划解DP问题考虑n的m划分a1+...am=n对于每个ai都有ai>0,那么{ai-1}就对应了n-m的m划分,如果存在ai=0那么就对应了n的m-1划分。综上可得出如下递推关系dp[i][j]=dp[i][j-i]+dp[i-1][j]#include#include#includeusing namespace std;int dp[12][12];int main
poj 1742 Coins 动态规划,多重部分和问题,,数组得要重复利用,不然会MLE。。#include#include#includeusing namespace std;int dp[100000+2];int a[100+2];int c[100+2];int main(){ int n,m; while(scanf("%d %d",&n,&m)&&(n+m)!=0) { for(in
poj Common Subsequence 最长公共子序列 真的很水,,原谅我吧#include#include#include#includeusing namespace std;const int N=1002;int dp[N][N];char a[N],b[N];int main(){ while(scanf("%s %s",a,b)!=EOF) { int n=strlen(a); int m=strlen(b
poj 3624 Charm Bracelet 标准的01背包#include#includeusing namespace std;#define MAX_N 3405int w[MAX_N],d[MAX_N];int dp[12881];int main(){ int n,m; cin>>n>>m; memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) cin>>w[i]>
poj 3253 Fence Repair 类似Huffman编码,越短的板在二叉树中深度越大如排序后的序列:L1、L2、L3、L4、L5....LN(L1+L2)为最短的两个之后,插入L3、L4、L5....LN中重复上述步骤直至只剩一块板为止#include#include#includeusing namespace std;#define MAX_N 20002typedef long long ll;i
poj 3069Saruman's Army 贪心 #include#include#includeusing namespace std;#define MAX_N 1002int x[MAX_N];int r,n;int main(){ while(cin>>r>>n && r+n != -2) { for(int i=0;i<n;i++) cin>>x[i]; sort(x,x+n); int i=0,a
应届生如何写好简历 昨天写了些应届毕业生简历的常见问题,很多人觉得我太苛刻,觉得对应届生要求有点高;有的觉得看了后还是不会写。那么今天我们就来看看怎么才能做好。需要声明的是我帮不了太多人,只有那些对计算机科学真的有点兴趣的人可能觉得我说的有点用。这里写的东西仅仅是我们的观点,不代表别的公司也这么做或者应该这么做。* 没有必要撒谎写简历最差的策略就是撒谎了。这种欺骗本身就自相矛盾。你到底希望
zoj2136 最长上升子序列LIS O(NlgN)解法 题目链接:zoj2136讲当前最长上升子序列建一个数组,利用二分查找#includeusing namespace std;const int maxn = 1002;int a[maxn];int find(int *a,int len,int n){ int left = 0,right=len,mid=(left+right)/2; while(left<=rig
Linux下/proc目录简介 1. /proc目录Linux 内核提供了一种通过 /proc 文件系统,在运行时访问内核内部数据结构、改变内核设置的机制。proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间。它以文件系统的方式为访问系统内核数据的操作提供接口。用户和应用程序可以通过proc得到系统的信息,并可以改变内核的某些参数。由于系统的信息,如进程,是动态改变的,所以用户或应用程序读取proc文
KMP算法 int KMPMatch(char *s,char *p){ int next[100]; int i,j; i=0; j=0; getNext(p,next); while(i<strlen(s)) { if(j==-1||s[i]==p[j]) { i++;
LeetCode Question Difficulty Distribution 转自:LeetCode Question Difficulty Distribution : Sheet1 IDQuestionDiffFreqData StructureAlgorithms
linux grep命令 转自:http://www.cnblogs.com/end/archive/2012/02/21/2360965.html1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。2.格式gre