杰拉斯的博客

[ACM_NYOJ_270]Product of Digits

杰拉斯 杰拉斯 | 时间:2012-04-20, Fri | 18,340 views
编程算法 

Product of Digits

Time Limit: 1.0 second
Memory Limit: 16 MB

Description

Your task is to find the minimal positive integer number Q so that the product of digits of Q is exactly equal to N.

Input

The input contains the single integer number N (0 ≤ N ≤ 109).

Output

Your program should print to the output the only number Q. If such a number does not exist print −1.

(阅读全文…)

[ACM_HDU_1009]FatMouse' Trade(贪心入门)

杰拉斯 杰拉斯 | 时间:2012-04-18, Wed | 22,323 views
编程算法 

FatMouse' Trade

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

Description

FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.

Input

The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.

Output

For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.

(阅读全文…)

[ACM_NYOJ_15]括号匹配(二)

杰拉斯 杰拉斯 | 时间:2012-04-18, Wed | 18,675 views
编程算法 

括号匹配(二)

时间限制:1000 ms | 内存限制:65535 KB
难度:6

描述

给你一个字符串,里面只包含"(",")","[","]"四种符号,请问你需要至少添加多少个括号才能使这些括号匹配起来。
如:
[]是匹配的
([])[]是匹配的
((]是不匹配的
([)]是不匹配的

输入

第一行输入一个正整数N,表示测试数据组数(N<=10)
每组测试数据都只有一行,是一个字符串S,S中只包含以上所说的四种字符,S的长度不超过100

输出

对于每组测试数据都输出一个正整数,表示最少需要添加的括号的数量。每组测试输出占一行

(阅读全文…)

[ACM_NYOJ_2]括号匹配(一)

杰拉斯 杰拉斯 | 时间:2012-04-18, Wed | 17,211 views
编程算法 

括号配对问题

时间限制:3000 ms | 内存限制:65535 KB
难度:3

描述

现在,有一行括号序列,请你检查这行括号是否配对。

输入

第一行输入一个数N(0<N<=100),表示有N组测试数据。后面的N行输入多组输入数据,每组输入数据都是一个字符串S(S的长度小于10000,且S不是空串),测试数据组数少于5组。数据保证S中只含有"[","]","(",")"四种字符

输出

每组输入数据的输出占一行,如果该字符串中所含的括号是配对的,则输出Yes,如果不配对则输出No。

(阅读全文…)

[ACM_NYOJ_10]Skiing(深度优先搜索&动态规划)

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

Skiing

时间限制:3000 ms | 内存限制:65535 KB
难度:5

描述

Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子:

1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9

一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最长的一条。

(阅读全文…)