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

競プロ日記#25/04/22

Posted at

AtCoder

日立製作所 社会システム事業部 プログラミングコンテスト2020

A-Hitachi String

  • 文字数と文字の偶数番目奇数番目を場合分けを実装
int main() {
    string S;
    cin >> S;
    int N = S.length();
    if (N % 2 == 1){
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0){
            if (S[i] != 'h'){
                cout << "No" << endl;
                return 0;
            }
        }
        if (i % 2 == 1){
            if (S[i] != 'i'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

}

アルゴ式-どこまでも続く数列 (1)

  • 特になし
int main() {
    int X,d;
    cin >> X >> d;

    if (d == 0){
        cout << 1 << endl;
        return 0;
    }
    if (d > 0){
        cout << 2 << endl;
        return 0;
    }
    if (d < 0){
        cout << 3 << endl;
        return 0;
    }
}

アルゴ式-どこまでも続く数列 (2)

  • rで場合分けする。

アルゴ式-極限の計算 (1)

  • 0に向けて極限を取るのでx≠0前提でx+a+b/xを考えるとよい

アルゴ式-小さい数の個数

  • まだまだ二分探索の理解が浅いと痛感させられた。
  • どうしてもleftも動くというイメージが薄くなってしまう。
int main() {
    long long N,M;
    cin >> N >> M;
    vector<long long> A(N);
    for (long long i = 0;i < N;i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for (int i = 0;i < M;i++){
        long long B;
        cin >> B;
        long long left = 0;
        long long right = N - 1;
        
        while (left != right){
            long long mid = (left + right) / 2;
            if (A[mid] > B){
                right = mid;
            }else{
                left = mid + 1;
            }
        }
        cout << left << endl;
        
    }
}

※シンプルに数3の復習しないとまずいなって思いました。本当に

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