[JAVA] A story about a super beginner participating in the AtCoder contest for the first time (AtCoder Beginner Contest 140)

I will describe the feeling of participating in AtCoder as a practice and a memorandum.

environment

· Mac OS X 10.13.6 ・ Eclipse -Language used: Java8 (OpenJDK 1.8.0)

Trigger

It's been a month since I first learned Java at a vocational school. I was recommended to AOJ at the level where I could finally use the for statement. I had a good time solving AOJ's problem in Lunlun for about a week, but yesterday, I couldn't access it from the morning (crying) But I'm taking a break and want to solve some problems!

So I decided to go to the AtCoder page, which I had avoided saying "the contest is kind of scary".

AtCoder Beginner Contest 140 It will be held just today (9/7)! !! I pressed the join button with momentum. I participated in the following contests AtCoder Beginner Contest 140

result

スクリーンショット 2019-09-08 9.56.32.png スクリーンショット 2019-09-08 9.50.58.png

I was addicted to the B problem

Question B, 70 minutes at the end of the correct answer ... I couldn't figure out the C problem.

■ Causes of addiction to problem B

-Compile error with double brackets (()) in the if statement (No error in Eclipse) -If an element is assigned while turning with a for statement, the number of search characters in the array will be exceeded (ArrayIndexOutOfBoundsException error).

■ Problem and answer of B problem

Problem Problem B: Buffet
Correct answer
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[21];
		int[] B = new int[21];
		int[] C = new int[21];
		int i = 0;
		int cs = 0;
		int csSum = 0;

		for( i = 0; i < N ; i++) { //Input Store the input of the second line in the A array
			A[i] = sc.nextInt();
		}

		for( i = 0; i < N; i++) { //Input The input of the third line is stored in the B array
			B[i] = sc.nextInt();
		}

		for( i = 0; i < N-1; i++) { //Input Store the input of the 4th line in the C array
			C[i] = sc.nextInt();
		}
		
		for(i = 1; i <= N; i++) { //Repeat as many times as you ate the food
			int j = A[i-1];  //I didn't want to put the array in the search letter, so I assigned it as a painstaking measure
			if(A[i] == j+1) {  //If the dish before the dish you are currently eating is i+If the first
				cs = B[j-1] + C[j-1];  //B satisfaction+C satisfaction
			}else {  //If i+If not the first
				cs = B[j-1];
			}
			csSum += cs;  //Add to the total satisfaction obtained
		}
		System.out.println(csSum);
		sc.close();
	}
}

Summary

-See All Submissions and study the problems you have solved by looking at the answers of other people. ――I realized once again that the number of questions I had solved was small, and I will do more and more exercises. ――It's about time to study algorithms. (I only know bubble sort)

I referred to the following article!

Tips about AtCoder Contest (@ drken) What to do next after registering with AtCoder-If you solve this much, you can fight enough! Past questions selected 10 questions ~ (@ drken) [Qiita article creation method beginner's memorandum](https://qiita.com/U-MA/items/996ae933ae94c5711883#%E3%81%9D%E3%82%82%E3%81%9D%E3%82%82markdown % E8% A8% 98% E6% B3% 95% E3% 81% A3% E3% 81% A6% E3% 81% AA% E3% 82% 93% E3% 82% 84% E3% 81% AD% E3 % 82% 93) (@ U-MA)

Recommended Posts

A story about a super beginner participating in the AtCoder contest for the first time (AtCoder Beginner Contest 140)
A story about the JDK in the Java 11 era
The story of intentionally using try catch for the first time in my life
Impressions and doubts about using java for the first time in Android Studio
Modeling a Digimon with DDD for the first time Part 1
Solve AtCoder Beginner Contest 151 in java
Solve AtCoder Beginner Contest 150 in java
Solve AtCoder Beginner Contest 153 in java
Solve AtCoder Beginner Contest 175 in java
Solve AtCoder Beginner Contest 160 in java
Solve AtCoder Beginner Contest 152 in java
Solve AtCoder Beginner Contest 156 in java
Spring AOP for the first time
A story that a Ruby beginner made and released a LINE BOT that tells the train time in 2 months
Introduction to java for the first time # 2
[Beginner] A story about starting studying Java for job hunting ~ 2nd month ~
The story of releasing the Android app to the Play Store for the first time.
[Beginner] A story about starting studying Java for job hunting ~ 3rd month ~
[Beginner] A story about starting studying Java for job hunting ~ 1st month ~
Learning for the first time java [Introduction]
[Socket communication (Java)] Impressions of implementing Socket communication in practice for the first time
[Beginner] A story about starting studying Java for job hunting ~ 5th month ~
Programming for the first time in my life Java 1st Hello World
A story about changing skills from COBOL cultivated for 5 years in the late 20s to a Web language
[Beginner] A story about starting studying Java for job hunting ~ 4th month ~
I tried using Docker for the first time
The story of learning Java in the first programming
The story that docker had a hard time
Walls hit by Rspec for the first time
A story about making a Builder that inherits the Builder
Android Studio development for the first time (for beginners)
I tried touching Docker for the first time
A story about the JDK in the Java 11 era
A story about a super beginner participating in the AtCoder contest for the first time (AtCoder Beginner Contest 140)
A note about the seed function of Ruby on Rails
A story about speeding up unittest on Docker for Mac
A story about hitting the League Of Legends API with JAVA
A story about changing skills from COBOL cultivated for 5 years in the late 20s to a Web language
AtCoder Beginner Contest 168
AtCoder Beginner Contest 170 A, B, C up to ruby
A note for Initializing Fields in the Java tutorial
Oreore certificate https (2020/12/19) for the first time with nginx
Learning memo when learning Java for the first time (personal learning memo)
A story about introducing Evolutions into the Play Framework
A story about starting a Java-related book club for newcomers
How to study kotlin for the first time ~ Part 2 ~
How to study kotlin for the first time ~ Part 1 ~
A summary of what Java programmers find when reading Kotlin source for the first time
A story that I realized that I had to study as an engineer in the first place
[Rails] I tried using the button_to method for the first time
A story about BeanNotOfRequiredTypeException occurring after applying AOP in Spring
A story about speeding up unittest on Docker for Mac
With the software I've been making for a long time ...
[DL4J] Java deep learning for the first time (handwriting recognition using a fully connected neural network)
[Learning record] I got the current time in Ruby and output a different greeting for each time.
[Introduction] Setting up GridDB Community Edition in the CentOS container of Docker Desktop for the first time