0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AtCoder431の感想と自分が解いたところまでの解説を書いていきます
今回はAをC++, python, java, BをC++で解きます
AtCoder Beginner Contest 432
今回もちゃんと解説書きます

1.感想

A問題:
簡単だったが少し遠回りだったかもしれない
B問題:
next_permutation知っていれば簡単
C問題:
ほんとにわからん
E問題:
TLEがなければ...

2.結果

image.png
思ったよりも耐えてて嬉しい

3.解説

A問題 Permute to Maximize

大きい順にソートして出力するだけ

C++での解法

#include <bits/stdc++.h>
using namespace std;

int main(){
    vector<int> A(3);
    for (int &i : A) cin >> i;
    sort(A.rbegin(), A.rend());
    for (int i : A) cout << i;
    cout << endl;
    return 0;
}

pythonでの解法

A = reversed(sorted(list(map(int, input().split()))))

for i in A:
    print(i, end="")

print()

javaでの解法

import java.util.*;

public class Main{
    static Scanner javain = new Scanner(System.in);
    
    public static void main(String[] args){
        int[] A = new int[3];
        for (int i = 0; i < 3; i++) A[i] = javain.nextInt();
        sort(A);
        for (int i = 2; i >= 0; i--) System.out.print(A[i]);
        System.out.println();
    }
    
    public static void sort(int[] arr){
        for (int i = 0; i < arr.length; i++){
            for (int j = 0; j < arr.length; j++){
                if (arr[i] < arr[j]){
                    int tmp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = tmp;
                }
            }
        }
    }
}

B問題 Permute to Minimize

文字列として入力するのが大事
next_permutationで次の文字列を作って最初の文字が0以外で小さくなっていれば答えを変える

C++での解法

#include <bits/stdc++.h>
#define INF (1 << 30)
using namespace std;

signed main(){
    string S;
    cin >> S;
    int ans = INF;
    
    for (int i = 0; i < 125; i++){
        if (S[0] != '0' && ans > stoi(S)) ans = stoi(S);
        next_permutation(S.begin(), S.end());
    }
    
    cout << ans << endl;
    return 0;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?