AtCoder Beginner Contest 130

AtCoder Beginner Contest 130

https://atcoder.jp/contests/abc130
补补之前的

A - Rounding

#include <bits/stdc++.h>

using namespace std;

int main () {
    int a, b;
    cin >> a >> b;
    if (a < b)  cout << 0;
    else    cout << 10;
}

B - Bounding

#include <bits/stdc++.h>

using namespace std;

int main () {
    int n, m, x, sum = 0;
    bool find = false;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        sum += x;
        //cout << sum << endl;
        if (find)   continue;
        
        if (sum > m)   find = true, cout << i << endl;
    }
    if (!find)  cout << n + 1;
}

C - Rectangle Cutting

#include <bits/stdc++.h>

using namespace std;

int main () {
    double n, m, x, y;
    cin >> n >> m >> x >> y;
    cout << fixed << setprecision (9) << n * m / 2.0 << ' ';
    if (n / 2 == x && m / 2 == y)     cout << 1;
    else    cout << 0;
}

D - Enough Array

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 1e5 + 5;
int n, m, sum[N], ans;

signed main () {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)    cin >> sum[i], sum[i] += sum[i-1];
    int l = 1, r = 1;
    while (r <= n) {
        if (sum[r] - sum[l-1] < m)      r ++;
        else    ans += n - r + 1, l ++;  
    }
    cout << ans << endl;
}

E - Common Subsequence

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 2e3 + 5, mod = 1e9 + 7;
ll n, m, a[N], b[N], f[N][N]; //f[i][j]: a的前i项和b的前j项中有多少对不相同的公共子序列

int main () {
    cin >> n >> m;
    f[0][0] = 1;
    for (int i = 1; i <= n; i++)    cin >> a[i], f[i][0] = 1;
    for (int j = 1; j <= m; j++)    cin >> b[j], f[0][j] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            (f[i][j] += f[i-1][j] + f[i][j-1] - f[i-1][j-1] + mod) %= mod;
            if (a[i] == b[j])   (f[i][j] += f[i-1][j-1] + mod) %= mod;
        }
    }
    cout << f[n][m] << endl;
}

F - Minimum Bounding Box

分类讨论。

posted @ 2023-01-27 22:34  Sakana~  阅读(20)  评论(0编辑  收藏  举报