代码改变世界

编程之美:队列中的最大最小值

2015-01-03 11:09 by MengYu1, 371 阅读, 0 推荐, 收藏, 编辑
摘要:#include "iostream" #include "memory.h" #include "stdio.h" #include "limits.h" typedef int Type; const int MAXN=15; const int MIN=INT_MIN; class stack { public: stack() { stacktop=-1; ... 阅读全文

leetcode:Compare Version Numbers

2014-12-29 11:52 by MengYu1, 129 阅读, 0 推荐, 收藏, 编辑
摘要:Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 num2?1:-1; } return 0; } 这个题有意思的在于统一化的处理 先在串尾加顿号,这样每次都可以以顿号为判定条件 其次while (i<l1 || j<l2)这一句也很有意思... 阅读全文

leetcode:Search for a Range

2014-12-28 21:20 by MengYu1, 110 阅读, 0 推荐, 收藏, 编辑
摘要:Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in th... 阅读全文

csapp:无符号数可能造成的程序bug

2014-12-27 20:01 by MengYu1, 164 阅读, 0 推荐, 收藏, 编辑
摘要:出自csapp练习2.26 size_t strlen(const char *s); int strloner(char *s,char *t) { return strlen(s)-strlen(t); } 乍一看没什么问题,但是size_t是定义为unsigned int的,那么当s串长度小于t串,计算结果是负数,对于无符号数既是一个很大的无符号数,这样返回结果为1,结果错误 改正可... 阅读全文

leetcode:atoi

2014-12-14 12:32 by MengYu1, 124 阅读, 0 推荐, 收藏, 编辑
摘要:转换原则:忽略前导空格,从+-或数字开始转换,中间出现非数字break,注意判断乘法加法溢出,大于INT_MAX输出INT_MAX,小于INT_MIN输出INT_MIN int atoi(const char *str) { if (str==NULL) { return 0; } int ans=0,pos=1,pre; while (*s... 阅读全文

leetcode:min stack

2014-12-14 10:59 by MengYu1, 109 阅读, 0 推荐, 收藏, 编辑
摘要:实现O(1)时间取得栈最小值。基本思路是新建一个minstack的栈,维护minstack的从上到下递增序,栈顶位当前stack最小值。当push时比较如果比minstack栈顶小于或等于就push进去,pop的时候如果要pop的元素与minstack栈顶相等从minstack同时pop。class... 阅读全文

leetcode:Pascal's Triangle II

2014-12-09 17:34 by MengYu1, 82 阅读, 0 推荐, 收藏, 编辑
摘要:vector getRow(int rowIndex) { int *arr = new int[rowIndex+2]; int *arr1 = new int[rowIndex+2]; std::vector v; if (rowIndex == 0) { v.push_back(1); ... 阅读全文

opencv学习

2014-11-19 15:33 by MengYu1, 159 阅读, 0 推荐, 收藏, 编辑
摘要:使用查找表LUT #include #include #include using namespace std;using namespace cv;int main(int argc, char **argv){ double t = (double)getTickCount(); const char *srcfile = argv[1]; Mat srcimg; ... 阅读全文

使用mathtype在live writer中插入公式

2014-10-25 12:53 by MengYu1, 253 阅读, 1 推荐, 收藏, 编辑
摘要:博客园的官方贴中详细说明了怎么使用windows live writer(wlm)写博客http://home.cnblogs.com/group/topic/8550.html 下面我介绍下使用mathtype在wlm中插入公式 打开Preference下的第一个选项cut and copy preference下 选择windows live writer,之后编辑好公式,直接CTRL+A... 阅读全文

miller_robin大素数判定

2014-10-23 23:36 by MengYu1, 1352 阅读, 0 推荐, 收藏, 编辑
摘要:参考了ACdreamer大神的博客http://blog.csdn.net/acdreamers/article/details/7913786 在51nod上看了个10^30范围的素数判定,打表肯定是不行了,应该用miller-robin素数判定加java的BigInteger 首先基于fermat小定理就是gcd(a,p)=1时,a^(p-1)%p=1,所以在生成rand(2,p-1)的随机数... 阅读全文