AtCoder Beginners Contest 340の感想

今週は仕事が忙しく、1週間お化粧もできないほどだったのですが、土曜の19時に完了して、「このままABC受けられるな」という発想が起き、1週間ほとんどプログラミングをやっていませんでしたが、挑戦してみました。

総評

ノーミスでAとBは解けました。
Cは考えたけどダメだったのと、Dからはさっぱりです。
数学の問題っぽいものは意味はわかるのに実装できないなあ。としょんぼり見つめていました。

順位は6838位。
ratingは今回で+24で30になりました。

A「Arithmetic Progression

https://atcoder.jp/contests/abc340/tasks/abc340_a

等差数列。数学の公式をそのまんま書いて終了。
Bのことを末項のnだと勘違いして一瞬止まりましたが・・・

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int d = sc.nextInt();
        int n = (b - a) / d + 1;
        for (int i = 1; i <= n; i++) {
            System.out.print(a + (i - 1) * d);
            if (i != n) {
                System.out.print(" ");
            }
        }
        
    }
}

B「Append」

https://atcoder.jp/contests/abc340/tasks/abc340_b

解けたけどいまだによく分かってない問題です。(何がしたいんだ的な)

AC。これも割と簡潔に書けた気がする。

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        
        for (int i = 0; i < q; i++) {
            int key = sc.nextInt();
            if (key == 1) {
                a.add(sc.nextInt());
            } else {
                int y = sc.nextInt();
                System.out.println(a.get(a.size() - y));
            }
        }
    }
}


C「Divide and Divide」
https://atcoder.jp/contests/abc340/tasks/abc340_c

わかるのに解けなかったなあ。悔しいです。

途中まで書いたコードを載せておきます。

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        ArrayList<Integer> x = new ArrayList<>();
        x.add(n);
        
        int x1 = n;
        int x2 = n;
        int money = 0;
        
        for (int i = 0; i < 4; i++) {
            if (x.get(i) >= 2) {
                money += x1;
                x1 = x1 / 2; x2 = x1 - x1 / 2;
                x.add(x1);
                x.add(x2);
                System.out.println(x.get(i));
            }
        }
        
        System.out.print(money);
        
        
        /*
        int x = n
        int x1 = n / 2;
        System.out.print(x1);
        int x2 = n - x1;
        int money = 0;
        if (n >= 2) {
            money += n;
        }
        
        while (x >= 2) {
            int x = n / 2;
            int x2 = n - x;
            
            if (x >= 2) {
                money += 2 * x;
            } else if (x2 >= 2) {
                money += x2;
                x = x2;
            }
        }
        */
    }
}

ひとつわかったのは、ArrayListの要素すうが増えてもfor文のサイズで更新されるわけではないということ・・・
増えたら増えただけチェック数を増やしたかったのですが・・・