摘要:
在 STS 上,一个类引用在相同 package 中另一个类,但是报 cannot be resolved to a type 错误。 解决方法 : Alternatively, you can highlight the project : Choose Clean ... from Projec 阅读全文
摘要:
jsp 乱码 : The time on the server is 2016?2?7? ??10?45?32?. 在 jsp 中,用 jsp 语法添加 utf-8 字符集,可解决此问题 <%@ page contentType="text/html; charset=utf-8" language 阅读全文
摘要:
dojox.grid.EnhancedGrid 的介绍说, EnhancedGrid 是基于 DataGrid 提供增强功能的。EnhancedGrid (dojox.grid.EnhancedGrid) provides a rich set of features that enhance th... 阅读全文
摘要:
问题:找出所有小于 n 的素数。
题目很简洁,但是算法实现的优化层次有很多层。其中最主要思想的是采用 Sieve of Eratosthenes 算法来解答。
大思路为:
找出 n 范围内所有合数,并做标记。
未做标记的即为素数,统计未做标记的数个数即为原题目解。
如何找到 n 范围内所有合数?
将第一个素数 2 赋值给 i。
当 i 小于 n 时:(2)
对于以确定的素数 i ,将 i 的全部倍数标记为合数。(1)
离 i 最近的下一个未被标记为合数的数即为素数。将下一个素数赋值给 i .
上面算法有可以优化的地方:
(1)步骤找合数,无需从 2 开始算 i 的倍数,而是从 i 倍开始算,即 i*i。举个例子,当 i 为 5 时, 5*2, 5*3, 5*4 的记号,已经在 i 分别为 2,3,4的时候做了。所以,可以直接从 i 倍开始算。相应地,(2)步骤也可以优化 “为 i*i n 时”。 阅读全文