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

本日解いた問題

B - Uneven Numbers

B - Uneven Numbers
解答

#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;
  cin >> n;
  ll res = 0;
  for(int i = 1; i <= n; i++){
    string s = to_string(i);
    ll x = s.size();
    if(x%2==1) res++;
  }
  cout << res << endl;
}

解法

N以下で桁数が奇数になるものを全て数える。

B - 105

B - 105
解答

#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;
  cin >> n;
  ll res = 0;
  for(int i = 1; i <= n; i++){
    ll divi = 0;
    if(i%2==0)continue;
    for(int j = 1; j <= i; j++){
      if(i%j == 0) divi++;
    }
    if(divi==8) res++;
  }
  cout << res << endl;
}

解法

1からNまでの奇数において約数が何個になるか全探索を行い、出力する。

B - K-th Common Divisor

B - K-th Common Divisor
解答

#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 a, b, k;
  cin >> a >> b >> k;
  vec cnt(0);
  ll mmax = max(a, b);
  for(int i = 1; i <= mmax; i++){
    if(a%i==0 && b%i==0) cnt.push_back(i);
  }
  ll s = cnt.size();
  cout << cnt[s - k] << endl;
}

解法

ABどちらも割り切れる正整数を入れるための配列を用意する。その後全探索を行い配列に入れていき、K番目に大きいものを出力する。

D - Lucky PIN

D - Lucky PIN
解答

#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;
  cin >> n;
  string s;
  cin >> s;
  ll res = 0;
  for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
      for(int k = 0; k < 10; k++){
        ll cnt = 0;
        bool jud1=false,jud2=false,jud3= false;
        while(cnt < n){
          if(s[cnt] == i + '0') {
            jud1 = true;
            cnt++;
            break;
          }
          cnt++;
        }
        while(cnt < n){
          if(s[cnt] == j + '0') {
            jud2 = true;
            cnt++;
            break;
          }
          cnt++;
        }
        while(cnt < n){
          if(s[cnt] == k + '0') {
            jud3 = true;
            cnt++;
            break;
          }
          cnt++;
        }
        if(jud1&&jud2&&jud3) res++;
      }
    }
  }
  cout << res << endl;
}

解法

暗証番号は000から999までなので1桁ずつ考え、全探索を行う。暗証番号の最初の数字がSの要素に含まれていたら次の要素も含まれているか、のように探索を行うことで結果が求まる。

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?