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?

AtCoder 勉強記録[C++] その26

Posted at

AtCoderで入茶を目指して勉強しています。
勉強を継続するために投稿を始めました。
もともとアカウントを作成していましたが、今年の4月から本格的に勉強を始めました。
一応自分用に解法を書いていますが雑です、自分で読み返して困ったら修正します。
私のアカウント
解いた問題

本日解いた問題

本日はAtCoder Beginner Contest 363に参加した。今回のコンテストではC問題まで解くことができ、さらにD問題に取り組むことができた。また、初めて緑パフォーマンスを出せた。

A - Piling Up

A - Piling Up
解答

#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n;
  cin >> n;
  if(n < 100) cout << 100 - n << endl;
  else if(100 <= n && n < 200) cout << 200 - n << endl;
  else if(200 <= n && n < 300) cout << 300 - n << endl;
}

解法

100未満、100以上200未満、200以上300未満の場合に分けて処理することで結果が求まる。

B - Japanese Cursed Doll

B - Japanese Cursed Doll
解答

#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, t, p;
  cin >> n >> t >> p;
  vec l(n);
  rep(i, n) cin >> l[i];
  ll res = 0;
  while(1){
    ll cnt = 0;
    for(int i = 0; i < n; i++){
      if(l[i] >= t) cnt++;
      l[i]++;
    }
    if(cnt >= p) break;
    res++;
  }
  cout << res << endl;
}

解法

1日ごとに髪の毛の長さがT以上の人数と日数をカウントして、人数がP以上になったときにループを抜ける。その際の日数を出力する。

C - Avoid K Palindrome 2

C - Avoid K Palindrome 2
解答

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  ll cnt = 0;
  ll res = 0;
  sort(s.begin(), s.end());
  do {
    
    for(int i = 0; i <= n-k; i++){
      bool jud = true;
      for(int j = 0; j < k; j++){
       if(s[i+j] != s[i+k-1-j]) jud = false;
     }
     if(jud) {
       cnt++;
       break;
     }
    }
    res++;
  } while (next_permutation(s.begin(), s.end()));
  cout << res - cnt << endl;
}

解法

この問題では文字列Sを並び替えてえられる文字列を順列全探索で求める。並び替えた文字列に対して、長さKの部分文字列が回文かどうかを判定して、回文の場合をカウントしておく。その後、並び替えたすべての文字列の数から回文を含む数を引くことで結果が求まる。

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?