LoginSignup
0
0

More than 3 years have passed since last update.

AtCoder Beginner Contest 180

Posted at

A - box

C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    int n, a, b;
    cin >> n >> a >> b;

    cout << n - a + b << endl;
    return 0;
}

B - Various distances

Python
import math
N = int(input())
X = list(map(int, input().split()))

ans1 = 0
ans2 = 0
ans3 = 0

for i in range(0, N):
    X[i] = abs(X[i]);
    ans1 = ans1 + X[i];
    ans2 = ans2 + X[i] * X[i];

print(ans1);
print(math.sqrt(ans2));
print(max(X));

C - Cream puff

C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384

using namespace std;
using ll =long long;
using P = pair<int,int>;

vector<ll> divisor(ll n) {
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main(int argc, const char * argv[]) {
    ll N;
    cin >> N;

    vector<long long> Ans = divisor(N);
    rep(i, Ans.size()){
        cout << Ans[i] << endl;
    }

    return 0;
}

D - Takahashi Unevolved

C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384
#define ll_limit 2e18

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    ll X, Y, A, B;
    cin >> X >> Y >> A >> B;
    ll ans = 0;

    while((double)A*X<=2e18 && A*X<=A+B && A*X<Y){
        X*=A;
        ans++;
    }

    cout << ans+(Y-1-X)/B << endl;
    return 0;
}
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