1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

競プロ日記#25/04/19

Posted at

AtCoder

ABC142_A-Odds of Oddness

  • 特になし
  • 絶対誤差または相対誤差を1e-6以下にするためにfixed << setprecision(10)を使う。setprecision(10)の中は10が安心
int main() {
    int N;
    cin >> N;
    int total = 0;
    for (int i = 1; i <= N;i++){
        if (i % 2 != 0){
            total++;
        }
    }
    double ans = total / (double)N;
    cout << fixed << setprecision(10) << ans << endl;
}

ABC142_B-Roller Coaster

  • 特になし
  • 昇順でソートしてN回for文で回す。初めて身長がK以上になったらそれ以降の人たちもK以上の身長を持っているのでN - i人がKcm以上と分かる。
  • あとは誰一人Kcmを超えていない場合の考慮を加えて終わり
int main() {
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++){
        if (A[i] >= K){
            cout << N - i << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

ABC142_C-Go to School

  • 少し頭がこんがらがりそうだが、要は出席番号1からN順番にその人が何番目に登校したかという情報がA1~ANで入ってくるという話なので適切に並び替えてあげれば答えが出せる。
  • 空白区切りなので出力の仕方だけ少し注意
    -AtCoder ProblemsのBoot camp for Beginnersをやっているのだが昔のC問題の難易度がやさしめだったのかあまり練習にならない気がする(練習にならないは語弊だが最近のC問題は明らかにもっと難しい気がする...)
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    vector<int> ans(N);

    for (int i = 0; i < N; i++){
        ans[A[i] - 1] = i + 1;   
    }

    for (int i = 0; i < N; i++){
        if (i == N - 1){
            cout << ans[i] << endl;
            return 0;
        }
        cout << ans[i] << " ";
        
    }
    
}

ABC094_A-Cats and Dog

  • 特になし
  • 問題設定が多少ややこしい
int main() {
    int A,B,X;
    cin >> A >> B >> X;
    if (A + B > X && A <= X) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

ABC094_B-Toll Gates

  • 特になし
int main() {
    int N,M,X;
    cin >> N >> M >> X;
    int left = 0;
    int right = 0;
    for (int i = 0; i < M;i++){
        int a;
        cin >> a;
        if (a < X) {
            left++;
        } else {
            right++;
        }
    }

    cout << min(left, right) << endl;
}

アルゴ式-2乗和

  • nの2乗の総和について導出する問題

long long func(long long N){
    return N*(N+1)*(2*N+1) / 6;
} 

アルゴ式-ボールと箱 (3)

  • 手順的にはnCmで選んだものたちを階乗で並べるという流れだが、そもそもnCm = nPm / m!となるので結果としてnPm / m! * m!つまりnPmが求める値
int main() {
    int N,M;
    cin >> N >> M;

    cout << funcPermutation(N,M) << endl;

}
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?