2012年12月10日

Given an array S of n integers, are there elements x, y, z in S such that x + y + z = 0? Find all unique triplets in the array which gives the sum of zero.

Note:

  • Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)
  • The solution set must not contain duplicate triplets.

    一个重要的优化就是如果上个数已经求过集合了 例如[-1 -1 0 2 2]已经包含了[-1 0 2 2] 当然也包含了 [-1 0 2]集合的。

posted @ 2012-12-10 11:38 micheal's tech 阅读(188) | 评论 (0)编辑 收藏

2012年12月4日

#include <thread>

template <typename Duration, typename Function>
void timer(Duration const & d, Function const & f)
{
    std::thread([d,f](){
        std::this_thread::sleep_for(d);
        f();
    }).detach();
}

posted @ 2012-12-04 18:10 micheal's tech 阅读(1091) | 评论 (0)编辑 收藏

This problem is caused when including <windows.h> before <winsock2.h>. Try arrange your include list that <windows.h> is included after <winsock2.h> or define _WINSOCKAPI_ first:

先包含winsock2.h
再包含windows.h

posted @ 2012-12-04 15:39 micheal's tech 阅读(1282) | 评论 (0)编辑 收藏

2012年12月3日

普通类调用中必须吧zmq设置为指针 否则单纯构造无法初始化
直接用初始化列表

context(1),netsocket(zmq::socket_t(context, ZMQ_REP))

posted @ 2012-12-03 17:51 micheal's tech 阅读(356) | 评论 (0)编辑 收藏

2012年11月14日

看见费曼学习方法 我觉得可能管用,最近试一下。

posted @ 2012-11-14 10:17 micheal's tech 阅读(556) | 评论 (0)编辑 收藏

2012年5月17日

感觉动态规划中最难的部分是在寻找 从状态j到状态i的递归式,就像证明归纳法一样,你得找出具体的式子来。
top bottom
bottom up
1. Longest Increasing Subsequence:
L[i] = max(1+L(j))(j<l && a[j]<a[i])
//if not exist any a[j]<a[i]
L[i] = 1;

getmaxvalueof array a[]


2. Maximum Sum Increasing Subsequence
almost same with above

3. Maximum continous sum

4. rod cutting

posted @ 2012-05-17 09:54 micheal's tech 阅读(410) | 评论 (0)编辑 收藏

2012年4月17日

最近在stackexchange网站上看到了一个非常好的问答,有人问:你做过的最有效的提高你的编程水平的一件事情是什么? 回首作为一个程序员这些年来的生活和职业道路,我使用了很多种不同的方法来提高我的编程技能 —— 阅读代码,编写程序,阅读书籍,听讲座,看视频,等等。 我的问题是:你做过的最有效的提高你的编程水平的一件事情是什么?对于那些想提高水平的程序员,你的建议是什么? 我希望你们提供的答案是各种各样的,并且不是那种“放之四海而皆准”的答案 —— 我希望得到适用于不同人的不同的答案。 有很多人给出了自己的答案,在这里,我将其中最受认可的前三种答案选出来翻译给大家。 最受欢迎的回答:学无止境 没有特别的先后次序… 和比自己更聪明的人一起工作永远乐意听取他人的意见,不管对方是低级水平,一般水平,资深,还是大师。职称头衔并不代表一切。学习其它的框架/语言,学习它们是的工作原理和思想,拿它们跟你已知的技术做比较。学习各种设计模式,最佳实践理论,然后用它们检查自己先前的知识,在需要的时候使用这些模式。结对编程 反对Joel说的一切。 第二受欢迎的回答:成为多面手 争取成为一个‘多面手万事通’ 在我职业生涯的早期,我在一种数据库和编程语言上是个专家。不幸的是,这种数据库在“数据库战争”中落败了,我才发现我的职业道路…很窄。在此之后,我下定决心以后决不能把自己封在一个小空间里。我开始学习所有手头上能接触到的东西:Windows,Unix,C,C++,Java,C#,Perl,Python,Access,SQL Server,Oracle,Informix,MySQL,等等。不管什么样的新的,不常见的工具或技术,我都成为“大拿” —— “去问克雷格(作者自己),他要是不会,他会去学会的。”结果,我做了各种各样的项目,从为环境监测做嵌入式系统,到为导弹防御做命令和控制系统。 我在各种的公司里唯一遇到的问题是:它们坚持要把我固定在一个专门的研究方向内,而我的专门研究是要成为一个多面手。[编辑:也叫做学识渊博的人或多才多艺的人或多领域专家。] 有些事情需要留意 … 高科技界里知识的半衰期是多少?根据摩尔定律(Moore’s law):18-24月内,半数你学到的知识都会过时。错误的遵循这种规律的专家会轻易的在这种技术发展的压力崩溃;一个多面手要做的事就是不断的丰富自己的技能,并从应用这些技能的经历中吸取教训。 第三受欢迎的回答:不要跟臭棋篓子下棋 我一直认为自己在不错的程序员中也算是个“灌篮高手”。直到有个家伙——我们叫他艾伦——被招进团队。艾伦很显然在很多方面都比我优秀。也比我年轻。他让我认识到,在过去的这些年里,我没有多少长进。我是一个特定技术方向的程序员,而且是水平一般。 这惊醒我应该自觉的不断提高自己的水平,特别是我写的代码的水平。 艾伦引导我学会了很多东西。他告诉我,大部分我写的代码在今后的数年里都将一直维护和进行扩展,写代码时要将这点铭记在心。我应该为我的代码写自动测试程序。艾伦说代码的开发一定不能停止在第一版上,应该不断的重构,提炼,让它达到完美。我发现,我对这些语言和工具的使用都还有还很大的改进空间。 从艾伦那我学到的最重要的一件事情是:永远不要停止学习。 数年后,艾伦离开了公司。我的心里突然感觉空荡荡的。这些年与他为伴让我在技能上提升到了一个全新的水平,我知道现在我比团队里的其他人优秀很多。他们仍然写着糟糕的代码,犯着以前犯过的错误。我努力教育他们,但他们对此不感兴趣。事实上,他们讨厌有人这样傲慢自大的指出他们犯的错误。 于是,几个月后,我也离开这这个公司。我去了一个很小的公司,在一个很出色的团队里工作。那里每个人都渴望学习更多知识,我喜欢这样的。 我很幸运能遇到艾伦。没有他,我也许现在仍然待在那家死气沉沉的公司和那帮食古不化的家伙在一起,哪都去不了,想的全是自己的私利。 这个讨论在stackexchange网站上的地址是这里。 从我个人而言,我觉得第三个答案对我最有价值,不知各位同行们有什么感受?请写在评论里与大家分享。

posted @ 2012-04-17 08:40 micheal's tech 阅读(373) | 评论 (1)编辑 收藏

2012年4月12日

今天开始记录

posted @ 2012-04-12 13:56 micheal's tech 阅读(259) | 评论 (0)编辑 收藏

2009年12月1日

VS 2008 uninstall package.



upgrade code.



posted @ 2009-12-01 17:20 micheal's tech 阅读(292) | 评论 (0)编辑 收藏

2009年11月17日

How can I run another application or batch file from my Visual C# .NET code?

Published 01 June 04 11:54 PM

Posted by: Duncan Mackenzie, MSDN
This post applies to Visual C# .NET 2002/2003

Suppose you want to run a command line application, open up another Windows program, or even bring up the default web browser or email program... how can you do this from your C# code?

The answer for all of these examples is the same, you can use the classes and methods in System.Diagnostics.Process to accomplish these tasks and more.

Example 1. Running a command line application, without concern for the results:

private void simpleRun_Click(object sender, System.EventArgs e){
 System.Diagnostics.Process.Start(@"C:\listfiles.bat");
}

Example 2. Retrieving the results and waiting until the process stops (running the process synchronously):

private void runSyncAndGetResults_Click(object sender, System.EventArgs e){
 System.Diagnostics.ProcessStartInfo psi =
  
new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat");
 psi.RedirectStandardOutput =
true;
 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
 psi.UseShellExecute =
false;
 System.Diagnostics.Process listFiles;
 listFiles = System.Diagnostics.Process.Start(psi);
 System.IO.StreamReader myOutput = listFiles.StandardOutput;
 listFiles.WaitForExit(2000);
 
if (listFiles.HasExited)
 {
  
string output = myOutput.ReadToEnd();
  
this.processResults.Text = output;
 }
}

 Example 3. Displaying a URL using the default browser on the user's machine:

private void launchURL_Click(object sender, System.EventArgs e){
 
string targetURL = @http://www.duncanmackenzie.net;
 System.Diagnostics.Process.Start(targetURL);
}

In my opinion, you are much better off following the third example for URLs, as opposed to executing IE with the URL as an argument. The code shown for Example 3 will launch the user's default browser, which may or may not be IE; you are more likely to provide the user with the experience they want and you will be taking advantage of the browser that is most likely to have up-to-date connection information.

C# code download available from http://www.duncanmackenzie.net/Samples/default.aspx

By the way, this post is a simple port of an earlier VB FAQ post... just in case you thought you had seen it already in your feeds...

posted @ 2009-11-17 13:10 micheal's tech 阅读(273) | 评论 (0)编辑 收藏

仅列出标题  下一页