Loading

Sumitomo Mitsui Trust Bank Programming Contest 2019

A - November 30

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int a, b, c, d;
int main() {
    cin >> a >> b >> c >> d;
    if (a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12) {
        if (b == 31)
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
    else if (a == 2) {
        if (b == 28)
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
    else{
        if (b == 30)
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
    return 0;
}

B - Tax Rate

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= 50000; i++) {
        if (int(double(i) * 1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

C - 100 to 105

完全背包

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;
typedef long long LL;
int dp[N];
int a[6] = {100, 101, 102, 103, 104, 105};
int main() {
    int x;
    cin >> x;
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    for (int i = 0; i < 6; i++) {
        for (int j = a[i]; j <= 1e5; j++) {
            dp[j] |= dp[j - a[i]];
        }
    }
    cout << dp[x] << endl;
    return 0;
}

D - Lucky PIN

给出一个长度为n的数字字符串,问从中取出3个数,能组成的不同的pin码有多少

dp:

#include <bits/stdc++.h>

using namespace std;

const int N = 3e4 + 5;
typedef long long LL;
int dp[N][1000][5];
char a[N];
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= 999; j++) {
            for (int k = 0; k <= 3; k++) {
                if (dp[i - 1][j][k] == 0) continue;
                dp[i][j][k] = 1;
                if (k <= 2) {
                    dp[i][j * 10 + a[i] - '0'][k + 1] = 1;
                }
            }
        }
    }
    int res = 0;
    for (int i = 0; i <= 1000; i++) {
        res += dp[n][i][3];
    }
    cout << res << endl;
    return 0;
}

E - Colorful Hats 2

n个人,3种颜色,每个人会说左边有多少个和他颜色相同的人,问一共有多少种情况

维护三个颜色的人数,然后模拟即可

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
LL const mod = 1000000007;
LL res = 1;
int main() {
    int n;
    int a[3] = {0, 0, 0};
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x, pos=0, cnt = 0;
        cin >> x;
        for (int j = 0; j < 3; j++) {
            if (a[j] == x) {
                cnt++;
                pos = j;
            }
        }
        res *= cnt;
        res %= mod;
        a[pos]++;
    }
    cout << res << endl;
    return 0;
}

F - Interval Running

Takahashi 和 Aoki在向同一个方向跑步,Takahashi在前T1分钟以A1的速度跑,后T2分钟以A2的速度跑,Aoki在前T1分钟以B1的速度跑,后T2分钟以B2的速度跑,问能相遇多少次?若相遇无数次则输出"infinity"

相遇无数次肯定是这两个人每(T1+T2)时间跑的路程相等。

否则判断谁的路程小,如果小的那个人的第一段路程比大的那个人大,就求一下这样循环多少次,会使它们不能相遇即可,否则不会相遇

#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long LL;
signed main() {
    int T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    if (A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2) {
        cout << "infinity" << endl;
        return 0;
    }
    A1 *= T1;
    A2 *= T2;
    B1 *= T1;
    B2 *= T2;
    if (A1 + A2 > B1 + B2) {
        swap(A1, B1);
        swap(A2, B2);
    }
    if (A1 > B1) {
        int r = (A1 - B1) / (B1 + B2 - A1 - A2);
        int res = 2 * r;
        if ((A1 - B1) % (B1 + B2 - A1 - A2)) res++;
        cout << res << endl;
    } else
        cout << 0 << endl;
    return 0;
}

posted @ 2021-02-16 09:45  WinterFa1L  阅读(88)  评论(0编辑  收藏  举报