[JAVA] ABC --017 --A & B & C

AtCoder ABC 017 A&B&C AtCoder - 017

A --Procon

	private void solveA() {
		int res = 0;
		for (int i = 0; i < 3; i++) {
			int point = nextInt();
			int ratio = nextInt();
			res += point * ratio / 10;
		}

		out.println(res);
	}

B --choku

--If'ch''o''k''u'is included, it will not be a choku word --If you replace all'ch''o''k''u'with empty strings, the length of the input value becomes 0. ――I think it's okay to check one by one instead of replacing, but java is easier to replace.

	private void solveB() {
		String res = next().replaceAll("ch", "").replaceAll("o", "").replaceAll("k", "").replaceAll("u", "");

		out.println(res.length() == 0 ? "YES" : "NO");
	}

C-High score

Loop (partial point 30 + 70 / TLE)

--From the problem -Don't take all kinds of jewels ――Which of the 1-n types of gems is the most rewarding to not take? Can be read as ―― Which ruins are you exploring? Which gem should not be taken, not ? Think with ` ――If you want to take a certain kind of gemstone, you should also take all the same kind of gemstones from other archaeological sites.

--If you read the question, it will be find the maximum score when you do not take a certain jewel. -$ If you don't take jewel 1, if you don't take jewel 2, if you don't take jewel 3 ... If you don't take jewel N $ ――If you simply turn the loop, it will never be in time, so try it like a cumulative sum

--Input example 1:

4 6 1 3 30 2 3 40 3 6 25 6 6 10

――For example, if you decide not to take 1 jewel, it will be as follows --You can't go to Ruins 1 --Ruins 2 and 3 can be reached --Ruins 4 cannot be visited --If you do not take 1-3, you will not get this score, but if you decide not to take 4-6, you will get this score.

Jewel 1 Jewel 2 Jewel 3 Jewel 4 Jewel 5 Jewel 6
Ruins 1 30 30 30
Ruins 2 40 40 40 40
Ruins 3 25 25
Ruins 4 10 10 10 10 10
total
(Maximum value without jewels)
75 35 10 80 80 70

――If this is the case, the last one will not be included ――However, I felt that the cumulative sum part could be implemented by the Imos method, so I tried another solution.

	private void solveC2() {
		int n = nextInt();
		int m = nextInt();

		int[] l = new int[n];
		int[] r = new int[n];
		int[] s = new int[n];
		int[][] res = new int[m + 1][1];
		for (int i = 0; i < n; i++) {
			l[i] = nextInt();
			r[i] = nextInt();
			s[i] = nextInt();
			for (int j = 1; j <= m; j++) {
				if (j < l[i] || r[i] < j) {
					res[j][0] += s[i];
				}
			}
		}

		Arrays.sort(res, (x, y) -> -Integer.compare(x[0], y[0]));
		out.println(res[0][0]);
	}

Potato method (101-point solution method)

--Reference site (potato method and cumulative sum) -Imotz method -Summary of imos method / cumulative sum problem in competitive programming -Be able to write the cumulative sum without thinking! - ABC - 035- A&B&C

Corrected the following part of the above solution

			for (int j = 1; j <= m; j++) {
				if (j < l[i] || r[i] < j) {
					res[j][0] += s[i];
				}
			}
	private void solveC() {
		int n = nextInt();
		int m = nextInt();

		int[] l = new int[n];
		int[] r = new int[n];
		int[] s = new int[n];
		int[] res = new int[m];
		for (int i = 0; i < n; i++) {
			l[i] = nextInt() - 1;
			r[i] = nextInt() - 1;
			s[i] = nextInt();
			res[0] += s[i];
			res[l[i]] -= s[i];
			if (r[i] < m - 1) {
				res[r[i] + 1] += s[i];
			}
		}

		for (int i = 1; i < res.length; i++) {
			res[i] = res[i] + res[i - 1];
		}
		Arrays.sort(res);
		out.println(res[m - 1]);
	}

Recommended Posts

ABC --023 --A & B & C
ABC --036-A & B & C
ABC --010 --A & B & C
ABC --028 --A & B & C
ABC --015 --A & B & C
ABC --128 --A & B & C
ABC --012-A & B & C
ABC --018 --A & B & C
ABC --054 --A & B & C
ABC --017 --A & B & C
ABC --029- A & B & C
ABC --022 --A & B & C
ABC --019 --A & B & C
ABC --020 --A & B & C
ABC --030- A & B & C
ABC --127 --A & B & C
ABC --007 --A & B & C
ABC --132- A & B & C
ABC --026 --A & B & C
ABC --014- A & B & C
ABC --016 --A & B & C
ABC --011-A & B & C
ABC --031 --A & B & C
ABC --021 --A & B & C
ABC --025 --A & B & C
ABC --024 --A & B & C
ABC --027 --A & B & C
ABC --080- A & B & C
ABC --133- A & B & C & D
ABC --122 --A & B & C & D
ABC --125- A & B & C & D
ABC --130- A & B & C & D
ABC --126 --A & B & C & D
ABC --134- A & B & C & D & E
ABC --131- A & B & C & D & E
diverta 2019 Programming Contest A & B & C & D
atcoder ABC113 C problem
ABC093 C --Same Integers
atcoder ABC115 C problem
AtCoder Beginner Contest 170 A, B, C up to ruby
A person writing C ++ tried writing Java
Make a SOAP call in C #
Call a C function from Swift
NLP4J [006-034] 100 language processing knocks with NLP4J # 34 "A B"