LoginSignup
1
1

More than 3 years have passed since last update.

ABC196 振り返りメモ(C問題まで)

Last updated at Posted at 2021-03-21

結果

ABCまでの3完で, レート変化は695722(+27)

A問題 ( Difference Max )

概要

a <= x <= b, c <= y <= d の時の, x - y の最大値

方針

x は大きく, y は小さくすれば良いので, b - c で OK.
コンテスト中は思いつかず, 全探索してしまった.

C++ での実装例は以下のようになる.

a.cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << b - c << endl;
} 

B問題 ( Round Down )

概要

N の小数点以下を切り捨てて出力する.

入力を文字列で受け取り, ピリオドより前の数字を出力すれば良い.
このような問題は Python だと簡潔に書ける.

方針

Python での実装例は以下のようになる.

b.py
x = input()
x = x.split('.')[0]
print(x)

C問題 ( Doubled )

概要

1 以上 N 以下の整数で, 十進表記は偶数桁であり, その前半と後半は文字列として等しいものの個数を求める.

方針

6桁の数字を全探索して, それと同じものをくっつけた数字が N 以下になるものを数えれば良い.
(例) i = 345 のときは, 345345 が N 以下になるかを考える.
また, N を越すような i が出てきたら, それ以降は全部 N を越すので, その時点で break して良い.

C++ での実装例は以下のようになる.

c.cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll n; cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= 1000000; i++) {
        if (stoll(to_string(i) + to_string(i)) <= n) ans++;
        else break;
    }
    cout << ans << 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