@ZHANGQIANYI2020
@[TOC](HNUCM-OJ 击鼓传花,Welcome,解密,数字三角形之备忘录法,数字三角形之动态规划法,最长公共子序列问题(LCS)之备忘录法)
问题 A: 击鼓传花
(时间限制: 1 Sec 内存限制: 128 MB)
题目描述:
岳麓山下旌旗卷,新月湖畔起歌声。湖南中医药大学运动会隆重开幕了,小 Q 所在的班级参加了“击鼓
传花”趣味比赛。
比赛规则如下,n 个队员 (不包括小 Q) 围成一个圈,每个人手里拿着一些花束 (数量也可能为 0),小 Q
站在圆圈的中间,队员需要传递花束给小 Q,每个鼓点只允许一个人传送一束花,最终要求圆圈上所有
人的花束都传递给小 Q。请问需要花多少鼓点呢?
输入:
多组数据。
第一行 n,代表队员数量。
第 2 行到第 n+1 行,每行一个整数 a[i],代表每个队员最开始拿的花束数量。
0 ≤ a[i] ≤ 106
所有组的 n 之和不超过 103
输出:
一个整数,代表需要的鼓点数。
样例输入:
4
1
2
5
4
样例输出:
12
参考答案:
import java.util.Scanner;
public class Main {
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
while (sc.hasNext()){
int n=sc.nextInt();
long s = 0;
for (int i = 1; i <= n; i++){
int a=sc.nextInt();
s+=a;
}
System.out.println(s);
}
}
}
问题 B: Welcome
(时间限制: 1 Sec 内存限制: 128 MB)
题目描述:
”How happy we are, To meet friends from afar!”
Welcome to Hunan University of Chinese Medicine!
Hope all of you can enjoy the competition ^ v ^
Now your task is to read an integer w and output the character painting of ”HNUCM”, there are w
space(s) (space are represented by dot) between two letters. Please refer to the sample for the specific
format.
输入:
There are several test files and each contains one case.
The input contains only 1 integer w (1 ≤ w ≤ 2018).
输出:
The output has 5 lines, each line has 25+4w characters which only contains ’o’(lowercase letter ’o’) and
’.’(English period ’.’)
样例输入:
1
样例输出:
o...o.o...o.o...o.ooooo.o...o
o...o.oo..o.o...o.o.....oo.oo
ooooo.o.o.o.o...o.o.....o.o.o
o...o.o..oo.o...o.o.....o...o
o...o.o...o.ooooo.ooooo.o...o
参考答案:
import java.util.Scanner;
public class Main {
static int w = 0;
public static void print1(){
for (int i = 1; i <= w; i++)
System.out.print(".");
}
private static void print2(){
System.out.print("o...o");print1();System.out.print("o...o");print1();System.out.print("o...o");print1();System.out.print("ooooo");print1();System.out