石子合并

N堆石子摆成一条线。现要将石子有次序地合并成一堆。规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的代价。计算将N堆石子合并成一堆的最小代价。
例如: 1 2 3 4,有不少合并方法
1 2 3 4 => 3 3 4(3) => 6 4(9) => 10(19)
1 2 3 4 => 1 5 4(5) => 1 9(14) => 10(24)
1 2 3 4 => 1 2 7(7) => 3 7(10) => 10(20)
括号里面为总代价可以看出,第一种方法的代价最低,现在给出n堆石子的数量,计算最小合并代价。

继续阅读石子合并

【二叉树】前序遍历+中序遍历->建树

描述输入一棵二叉树的先序和中序遍历序列,输出其后序遍历序列。输入输入文件为tree.in,共两行,第一行一个字符串,表示树的先序遍历,第二行一个字符串,表示树的中序遍历。树的结点一律用小写字母表示。输出输出文件为tree.out,仅一行,表示树的后序遍历序列。

样例输入

abdec
dbeac

样例输出

debca

继续阅读【二叉树】前序遍历+中序遍历->建树

SDAU训练日志第61篇(2019年4月13日)

今天因为身体不是很舒服,所以下午的比赛在宿舍单打的没去实验室。

前两题都以前刷过原题或者类似的,很顺的就A了,后两题有些马虎WA了几次,然后困得不行,躺了一会,起来肝了G。当我才5题的时候,发现18级的大佬们已经9题还差一个就AK了,心里不是滋味,菜是原罪,继续加油吧。

【STL/思维】King of Karaoke

题意:

It’s Karaoke time! DreamGrid is performing the song Powder Snow in the game King of Karaoke. The song performed by DreamGrid can be considered as an integer sequence , and the standard version of the song can be considered as another integer sequence . The score is the number of integers satisfying and .

As a good tuner, DreamGrid can choose an integer (can be positive, 0, or negative) as his tune and add to every element in . Can you help him maximize his score by choosing a proper tune?

Input
There are multiple test cases. The first line of the input contains an integer (about 100), indicating the number of test cases. For each test case:

The first line contains one integer (), indicating the length of the sequences and .

The second line contains integers (), indicating the song performed by DreamGrid.

The third line contains integers (), indicating the standard version of the song.

It’s guaranteed that at most 5 test cases have .

Output
For each test case output one line containing one integer, indicating the maximum possible score. 继续阅读【STL/思维】King of Karaoke

【JSP】在线聊天室

作业内容:

实现一个web聊天室,思路:可以将聊天信息放到application对象中。设计三个页面:主页面index.jsp包含两部分:上面是iframe,放置content.jsp,用于从application中取出聊天信息并显示,几秒刷新一次。下面是发送聊天信息的表单。表单提交给addinfo.jsp,用于将表单提交的信息存到application中。聊天信息只保留最新的5条。(提示:可以用List存储聊天信息)。

继续阅读【JSP】在线聊天室