주간 훈련

23326 단어 자바
첫 번 째 문제: 비 존 챔피언 은 단지 비 전 입 니 다. 그 는 또한 "비 존"팀 의 마음 에 드 는. 경쟁 에서 "비 존"은 다음 과 같은 문 제 를 가지 고: "당신 은 두 가지 다른 단어 (영어 문자 의 문자열), s 와 t. 당신 은 단어 t 로 단 어 를 변환 해 야 합 니 다". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more. Bizon the Champion wonders whether the “Bizons” can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.
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]));
		}
	}
}

좋은 웹페이지 즐겨찾기