杰拉斯的博客

[ACM_ZJUT_1058]Humble Numbers

杰拉斯 杰拉斯 | 时间:2012-04-10, Tue | 6,271 views
编程算法 

Humble Numbers

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8472 Accepted Submission(s): 3684

Description

A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers.

Write a program to find and print the nth element in this sequence

Input

The input consists of one or more test cases. Each test case consists of one integer n with 1 <= n <= 5842. Input is terminated by a value of zero (0) for n.

Output

For each test case, print one line saying "The nth humble number is number.". Depending on the value of n, the correct suffix "st", "nd", "rd", or "th" for the ordinal number nth has to be used like it is shown in the sample output.

(阅读全文…)

[ACM_ZJUT_1021]ACMICPC(暴力破解VS动态规划)

杰拉斯 杰拉斯 | 时间:2012-04-09, Mon | 17,990 views
编程算法 

ACMICPC

Time Limit:1000MS Memory Limit:32768K
Description:

Description

大写字母A-Z分别对应整数[-13,12],因此,一个字符串对应了一个整数列。我们把字符串对应的整数列的和称为该字符串的特性值。例如:字符串ACM对应的整数列为{-13,-11,-1},则ACM的特性值为(-13)+(-11)+(-1)=-25;其子串AC的特性值为-24;子串M的特性值为-1。 给你一个字符串,请找出该字符串的所有子串的最大特性值。

Input

第一行的正整数 N(1<=N<=1000)表示其后有N组测试数据,每组测试数据都由一个字符串组成。字符串只能由大写字母A-Z组成,且字符串的长度不会超过1000。

Output

输出有N行,每行是一组测试数据的输出结果。

(阅读全文…)

[第11届华南农业大学ACM程序设计竞赛 网络同步赛]题目及现场作答代码

杰拉斯 杰拉斯 | 时间:2012-04-07, Sat | 6,272 views
编程算法 

A. Local Minimum

Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 220 Accepted Submission(s) : 100

Description

There is an array contains n integers, no any 2 integers are same. Local minimum means an integer is less than its previous one and next one (ie. M[i-1] >M[i] < M[i + 1], 1 < i < n). The array is special, it is guarantee M[1] > M[2] and M[n - 1] < M[n]. Now, give you the array, please find out is there a local minimum exist in the array.

Input

The 1st line of input contains only 1 integer T (T <= 10), indicate the number of test cases.
The 1st line of each test case contains only 1 integer n (3 <= n <= 100), indicate the size of the array.
The 2nd line of each test case contains n integers, indicate the element of the array, the maximum of the integers will not exceed 100.

Output

For each test, if there is local minimum exist, please print "Yes", and otherwise print "No".

(阅读全文…)

[ACM_HDU_1421]搬寝室(动态规划经典问题)

杰拉斯 杰拉斯 | 时间:2012-04-06, Fri | 41,490 views
编程算法 

搬寝室

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7772 Accepted Submission(s): 2621

Description

搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整数,实在是太多了,于是xhd决定随便搬2*k件过去就行了.但还是会很累,因为2*k也不小是一个不大于n的整数.幸运的是xhd根据多年的搬东西的经验发现每搬一次的疲劳度是和左右手的物品的重量差的平方成正比(这里补充一句,xhd每次搬两件东西,左手一件右手一件).例如xhd左手拿重量为3的物品,右手拿重量为6的物品,则他搬完这次的疲劳度为(6-3)^2 = 9.现在可怜的xhd希望知道搬完这2*k件物品后的最佳状态是怎样的(也就是最低的疲劳度),请告诉他吧.

Input

每组输入数据有两行,第一行有两个数n,k(2<=2*k<=n<2000).第二行有n个整数分别表示n件物品的重量(重量是一个小于2^15的正整数).

Output

对应每组输入数据,输出数据只有一个表示他的最少的疲劳度,每个一行.

(阅读全文…)