Mryqu's Notes


  • 首页

  • 搜索
close

[算法] Elementary Sorts练习

时间: 2014-02-17   |   分类: Algorithm.DataStruct     |   阅读: 450 字 ~3分钟
本作业帖用于练习http://algs4.cs.princeton.edu/21elementary/里面的作业。 Stoogesort. Analyze the running time andcorrectness of the following recursive sorting algorithm: if theleftmost item is larger than the rightmost item, swap them. Ifthere are 2 or more items in the current subarray, (i) sort theinitial two-thirds of the array recursively, (ii) sort the finaltwo-thirds of the array, (iii) sort the initial two-thirds of thearray again. StoogeSort时间复杂度为O(_n_log3 / log 1.5 )= O(_n_2.7095…),比合并排序慢,甚至比冒泡排序慢,仅用于低效简单排序示范。 Guess-sort. Pick two indices i and j atrandom; if a[i] > a[j], then swap them.
阅读全文 »

[算法] UNION-FIND练习

时间: 2014-02-15   |   分类: Algorithm.DataStruct     |   阅读: 544 字 ~3分钟
本作业帖用于练习http://algs4.cs.princeton.edu/15uf/里面的作业。 True or false. Inthe quick union implementation, suppose weset id[p] to id[root(q)] insteadof setting id[root(p)] Would the resultingalgorithm be correct? 答案: 否。使用id[root(p)]可以将p所在连接全部合并到q所在连接,而使用id[p]仅会将p及其子连接合并到q所在连接。 Which of thefollowing arrays could not possibly occur during the execution ofweighted quick union with path compression: 0 1 2 3 4 5 67 8 9 7 3 8 3 4 5 68 8 1 6 3 8 0 4 5 69 8 1 0 0 0 0 0 0 00 0 0
阅读全文 »

[Git] 裸代码仓库和镜像代码仓库

时间: 2014-02-15   |   分类: Tool   Git     |   阅读: 243 字 ~2分钟
注:本文中操作都没有设置$GIT_DIR环境变量。 Git init和clone命令对bare和mirror参数的支持 ||–bare参数|–mirror参数 |—– |git init命令|支持|/ |git clone命令|支持|支持 裸代码仓库与普通代码仓库的区别 普通代码仓库裸代码仓库git init命令git init命令会创建一个空的Git代码仓库,一个在当前目录下包含hooks、info、objects和refs子目录和config、description和HEAD文件的.git目录。当前目录下可以创建工作树(工作文件和目录)。 config文件内容如下: [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnlygit init --bare命令会创建一个空的裸Git代码仓库,当前目录下直接创建hooks、info、objects和refs子目录和config、description和HEAD文件。裸Git代码仓库只包含版本控制信息而不包含工作树。 config文件内容如下: [core] repositoryformatversion = 0 filemode = false bare = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly git clone命令git clone命令会创建的一个包含.git子目录的目录,其中.git目录包含branches、hooks、info、logs、objects和refs子目录和config、description、HEAD、index和packed-refs文件。git clone命令所创建的目录中包含克隆的工作树(工作文件和目录)。 config文件内容如下: [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly [remote "
阅读全文 »

VirtualBox镜像资源

时间: 2014-02-05   |   分类: Tool     |   阅读: 2 字 ~1分钟
VirtualBox镜像资源: http://virtualboxes.org/images/

MinGW安装和使用

时间: 2014-02-04   |   分类: Tool     |   阅读: 30 字 ~1分钟
MinGW简介 MinGW全称Minimalist GNU For Windows,,是将GCC编译器和GNUBinutils移植到Win32平台下的产物,包括一系列头文件(Win32API)、库和可执行文件。MinGW是从Cygwin1.3基础上发展而来,相比Cygwin而言体积更小、使用更方便。MinGW分两个分支,MinGW(即MinGW32)和MinGW-w64。 MinGW包括: GNU编译器套件,包括C/C++、ADA语言和Fortran语言编译器 用于生成Windows二进制文件的GNU工具(编译器、链接器和档案管理器) 用于Windows平台安装和部署MinGW和MSYS的命令行安装器(mingw-get) 用于命令行安装器的GUI打包器(mingw-get-inst) MinGW安装和使用 我只想使用C/C++,所以仅安装mingw32-base、mingw32-gcc-g++。msys-base其实也是可以不用安装的,因为我可以使用已有的GitBash。 我选择了默认的安装路径c:\MinGW,可以将c:\MinGW\bin加入环境变量以便使用。 参考 MinGW 官方网站 SourceForge.net:MinGW - Minimalist GNU for Windows SourceForge.net:MinGW-w64 - for 32 and 64 bit Windows

处理注解@RequestParam的"Required String parameter is not present"

时间: 2014-02-04   |   分类: Service+JavaEE   Spring     |   阅读: 100 字 ~1分钟
最近玩一下SpringMVC,代码如下: @Controller @RequestMapping("/test.do") public class TestController { @RequestMapping(method = RequestMethod.GET) public ModelAndView sync(Model m, @RequestParam("fid") String fid, @RequestParam("sid") String sid) throws Exception { if(fid==null || sid==null) { m.addAttribute("file", new FileMetaDAO()); return new ModelAndView(ViewProvider.UPLOAD); } else { m.addAttribute("sync", new SyncDAO()); return new ModelAndView(ViewProvider.HR_SYNC); } } } 访问http://localhost:8080/hellorest/test.do 时发生如下问题: 查了一下Annotation Type RequestParam的javadoc,加上可选参数required解决战斗。 @Controller @RequestMapping("/test.do") public class TestController { @RequestMapping(method = RequestMethod.GET) public ModelAndView sync(Model m, @RequestParam(value="fid", required = false) String fid, @RequestParam(value="sid", required = false) String sid) throws Exception { if(fid==null || sid==null) { m.
阅读全文 »

免费私有代码托管平台

时间: 2014-02-01   |   分类: Tool     |   阅读: 16 字 ~1分钟
SourceForge、GitHub免费版、Gitorious免费版和GoogleCode等源代码仓库都要求项目必须开源。这里做一下免费私有代码托管平台资料汇总。 GitLab:支持Git库。首页说可以创建无限个私有或公开的库。使用时提示可以创建100000个级别为私有、GitLab内访问或公开的项目。 Atlassian公司的Bitbucket:支持Git库。公有和私有仓库都可以无限制创建,支持在线协作。免费版限制为5个用户。 Assembla:支持SVN/Git/Perforce库,支持在线协作。免费版限制为2个用户,一个私有库和500M存储。 beanstalk:支持SVN/Git库,支持在线协作。免费版限制为1个用户,一个私有库和100M存储。 unfuddle:有帖子说有免费帐户,但是没有找到。 开源中国的Git@OSC:支持Git库。最多可以创建 1000个项目,不限私有或者公开。 CSDN的CODE:支持Git库,支持在线协作。支持私有库和公开库。 京东的京东代码库:支持Git库。支持私有库和公开库。 参考 免费的Git私有代码托管服务 如何在“Google Code 代码托管”上建立私有代码版本库 Tortoisegit+BitBucket创造私有代码托管仓库

[算法] 算法课笔记-排序

时间: 2014-01-31   |   分类: Algorithm.DataStruct     |   阅读: 54 字 ~1分钟
排序算法分类 就地排序(inplace):排序算法所需辅助空间不依赖于元素个数N 稳定排序(stable):同键值的元素在排序后原相对顺序不变 排序算法对比 |排序算法|就地 排序|稳定 排序|最差时间 复杂度|平均时间 复杂度|最佳时间 复杂度|备注 |—– |选择排序(selection)|是||C=N²/2|C=N²/2 M=N|C=N²/2|C比较 M移动 |冒泡排序(Bubble)|是|是|C=N²/2|C=N²/2|C=N|当N较小或部分已排序时使用 |插入排序(insertion)|是|是|C=N²/2|C=N²/4 M=N²/4|C=N|当N较小或部分已排序时使用(部分已排序时,插入排序比选择排序要快) |希尔排序(shell)|是||?|?|C=N|严谨代码,次二次时间 |归并排序(merge)||是|C=NlgN|C=NlgN|C=NlgN|NlgN保证,稳定 Java中对对象排序 Perl, C++ stable sort, Python stable sort, Firefox JavaScript,… |快速排序(quick)|是||C=N²/2|C=2NlnN|C=NlgN|NlgN概率保证,实践中最快 Java中对原始数据类型排序 C qsort, Unix, Visual C++, Python, Matlab, Chrome JavaScript,… |三路基数快速排序 (3-way quick)|是||C=N²/2|C=2NlnN|C=N|当存在重复键值时改善快速排序 |堆排序(heap)|是||C=2NlgN|C=2NlgN|C=NlgN|NlgN保证,就地 选择排序 插入排序 希尔排序 Knuth Shuffle 合并排序 快速排序 快选 三路基数快速排序 堆排序

Hello Android!

时间: 2014-01-25   |   分类: Tech     |   阅读: 31 字 ~1分钟
第一次再简陋总比不做强! ADT安装 不经常装ADT (Android development tool),第二次装又犯晕了。 ADT要跟JDK平台一致: 对应32位JDK的adt-bundle-windows-x86-20131030.zip 对应64位JDK的adt-bundle-windows-x86_64-20131030.zip JDK装好久了,不知道是32位还是64位的了,可以跑一下下面的代码: public class JdkPlatformTest { public static voidmain(String[] args) { String arch =System.getProperty("sun.arch.data.model"); System.out.println(arch+"-bit"); } } 此外Windows平台可以通过下列命令获取:wmic os get osarchitecture Android虚拟设备仿真器操作命令 http://developer.android.com/tools/devices/emulator.html

使用Spring MVC下载Excel文件

时间: 2014-01-20   |   分类: Service+JavaEE   Spring     |   阅读: 46 字 ~1分钟
想使用Spring MVC下载Excel文件,照着下面的样例,很容易就实现了。 Spring MVC with Excel View Example (Apache POI and JExcelApi) Spring MVC and Excel file via AbstractExcelView 问题一:数据仅能生成xls,不能生成xlsx 通过org.springframework.web.servlet.view.document.AbstractExcelView源代码可知,Spring的AbstractExcelView仅支持HSSFWorkbook,不支持XSSFWorkbook。这一问题可以通过Github上的hmkcode/Spring-Framework来解决。 com.hmkcode.view.abstractview.AbstractExcelView com.hmkcode.view.ExcelView 问题二:下载的文件是我配置的视图路径export.do,而不是Excel后缀 通过在Rest Controller里添加如下代码解决: SimpleDateFormat myFmt=new SimpleDateFormat("yyyyMMdd_HHmmss"); response.setHeader("Pragma", "public"); response.setHeader("Cache-Control", "max-age=0"); if(excelVersion.equals("xlsx")){ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment; filename=test"+myFmt.format(new Date())+".xlsx"); }else{ response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=\"test"+myFmt.format(new Date())+".xls\""); }
46 47 48 49 50 51 52 53 54

Programmer & Architect

662 日志
27 分类
1472 标签
RSS 订阅
GitHub Twitter FB Page
© 2009 - 2023 Mryqu's Notes
Powered by - Hugo v0.120.4
Theme by - NexT
0%