杰拉斯的博客

归档:2012年2月月

[整理]ACM详解(4)——递归

杰拉斯 杰拉斯 | 时间:2012-02-17, Fri | 4,693 views
编程算法 

递归在解决一些问题的时候非常直观,但是在是使用递归的时候要注意递归的深度,如果深度太深,可能会造成堆栈溢出。下面通过实例介绍如何使用。

题目:超级楼梯
Problem Description
有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?
Input
输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。
Output
对于每个测试实例,请输出不同走法的数量

(阅读全文…)

[整理]ACM模拟题详解(3)——数论(续)

杰拉斯 杰拉斯 | 时间:2012-02-17, Fri | 4,504 views
编程算法 

5、Prime Ring Problem

Problem Description

A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime.

Note: the number of first circle should always be 1.

Input

n (0 < n < 20).

Output

The output format is shown as sample below. Each row represents a series of circle numbers in the ring beginning from 1 clockwisely and anticlockwisely. The order of numbers must satisfy the above requirements. Print solutions in lexicographical order.

You are to write a program that completes above process.

Print a blank line after each case.

(阅读全文…)

[整理]ACM模拟题详解(2)——简单数论

杰拉斯 杰拉斯 | 时间:2012-02-17, Fri | 8,197 views
编程算法 

有很多与数字相关的题目,主要考察基本的编程能力,如果数学比较好,对于解决这些问题有比较好的帮助。下面的题目是学生收集的题目,我进行了讲解。

1、Self Numbers

Description

In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence 33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ... The number n is called a generator of d(n). In the sequence above, 33 is a generator of 39, 39 is a generator of 51, 51 is a generator of 57, and so on. Some numbers have more than one generator: for example, 101 has two generators, 91 and 100. A number with no generators is a self-number. There are thirteen self-numbers less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97.

Input

No input for this problem.

Output

Write a program to output all positive self-numbers less than 10000 in increasing order, one per line.

(阅读全文…)

[整理]ACM模拟题讲解(1)-高精度

杰拉斯 杰拉斯 | 时间:2012-02-17, Fri | 5,468 views
编程算法 

Java中提供了byte、short、int和long表示整数,float和double来表示浮点数,每种类型都有一定的表示范围,当超过了这个范围之后就不能处理了。为了提供对非常大的整数和浮点数的处理,Java提供了BigDecimal和BigInteger。下面的代码演示了BigDecimal和BigInteger的基本用法:

BigDecimal data1 = new BigDecimal("23232123456789.123456789");
BigDecimal data2 = new BigDecimal("23423423123456789.123456789");
BigDecimal data3 = data1.add(data2);
System.out.println(data3.toString());
BigInteger iData1 = new BigInteger("123123123456456789789123456789");
BigInteger iData2 = new BigInteger("12312312323232456456789789123456789");
BigInteger iData3 = iData1.add(iData2);
System.out.println(iData3.toString());

如果不使用这些类库如何实现大整数和大浮点数的计算呢?下面通过ACM模拟题介绍。

(阅读全文…)

关于Web语义化

杰拉斯 杰拉斯 | 时间:2012-02-16, Thu | 5,923 views
前端开发 
“我们大部分人都有深刻体验,每当主流浏览器版本的升级,我们刚建立的网站就可能变得过时,
我们就需要升级或者重新建造一遍网站。例如1996-1999年典型的"浏览器大战",
为了兼容 Netscape 和 IE,网站不得不为这两种浏览器写不同的代码。同样的,
每当新的网络技术和交互设备的出现,我们也需要制作一个新版本来支持这种新技术或新设备,
例如支持手机上网的 WAP 技术。类似的问题举不胜举:网站代码臃肿、繁杂浪费了我们大量的带宽;
针对某种浏览器的 DHTML 特效,屏蔽了部分潜在的客户;不易用的代码,残障人士无法浏览网站等等。
这是一种恶性循环,是一种巨大的浪费。”

分离结构与表现的另一个重要方面是使用语义化的标记来构造文档内容。一个 XHTML 元素的存在就意味被标记内容的那部分有相应的结构化的意义,没有理由使用其他的标记。换句话说,不要让 CSS 使一个 HTML 元素看起来就像另一个 HTML 元素,比如用<div>来代替<p>标记标题。 首先是关于语义(Semantics)和默认样式的区别,默认样式是浏览器设定的一些常用tag的表现形式,个人认为他的主要目的就是让大家直观的认识标签(markup)和属性(attribute)的用途和作用,很明显Hx系列看起来很像标题,因为拥有粗体和较大的字号。<strong>,<em>用来区别于其他文字,起到了强调的作用。至于列表和表格很明显的告诉你他们是做什么的。 其次,语义化的网页的好处,最主要的就是对搜索引擎友好,又了良好的结构和语义你的网页内容自然容易被搜索引擎抓取,你网站的推广便可以省下不少的功夫。

(阅读全文…)