주간 훈련
23326 단어 자바
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
int s[] = new int[26];
int x = 0;
if (a.length() == b.length()) {
for (int i = 0; i < a.length(); i++)
s[a.charAt(i) - 97]++;
for (int i = 0; i < b.length(); i++)
s[b.charAt(i) - 97]--;
Arrays.sort(s);
if (s[0] < 0 || s[25] > 0)
System.out.println("need tree");
else
System.out.println("array");
} else if (a.length() > b.length()) {
boolean boo = true;
boolean bo = false;
for (int i = 0; i < a.length(); i++)
s[a.charAt(i) - 97]++;
for (int i = 0; i < b.length(); i++) {
s[b.charAt(i) - 97]--;
if (s[b.charAt(i) - 97] < 0) {
boo = false;
break;
}
}
if (boo) {
for (int i = 0, j = 0; i < a.length(); i++) {
if (a.charAt(i) == b.charAt(j)) {
j++;
x++;
}
if (x == b.length()) {
bo = true;
break;
}
}
if (bo)
System.out.println("automaton");
else
System.out.println("both");
} else
System.out.println("need tree");
} else
System.out.println("need tree");
}
}
두 번 째 문제, dp 마지막 으로, SIS 에서 농구 코트 가 열 렸 습 니 다, 그래서 Demid 는 농구 연습 세 션 을 개최 하기 로 결 정 했 습 니 다.. Students are numbered from 1 1 to n n in each row in order from left to right.
Now Demid wants to choose a team to play basketball. He will choose players from left to right, and the index of each chosen player (excluding the first one taken) will be strictly greater than the index of the previously chosen player. To avoid giving preference to one of the rows, Demid chooses students in such a way that no consecutive chosen students belong to the same row. The first student can be chosen among all 2n 2n students (there are no additional constraints), and a team can consist of any number of students. Demid thinks, that in order to compose a perfect team, he should choose students in such a way, that the total height of all chosen students is maximum possible. Help Demid to find the maximum possible total height of players in a team he can choose.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long x[] = new long[n];
long y[] = new long[n];
for (int i = 0; i < n; i++)
x[i] = sc.nextInt();
for (int i = 0; i < n; i++)
y[i] = sc.nextInt();
if (n == 1)
System.out.println(Math.max(x[0], y[0]));
else {
for (int i = 1; i < n; i++) {
x[i] = Math.max(y[i - 1] + x[i], x[i - 1]);
y[i] = Math.max(x[i - 1] + y[i], y[i - 1]);
}
System.out.println(Math.max(x[n - 1], y[n - 1]));
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.