牛客小白月赛88 (小白来了)

youhualiuh / 2024-03-09 / 原文

A.超级闪光牛可乐

思路:

n个不同名称 第i种提高Wi的诱惑值,之和不小于x就可以捕捉 零食不超过1000个超过输出-1不超过输出字符串即可

看一眼数据你会发现根本不需要考虑因为Wi的最小值是1所有直接输出任意的即可所有你只要一个ch即可后面直接输出即可不用管其他的

Code:

#include <bits/stdc++.h>
    
using namespace std; 

int main() {
    ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    int x, n; cin >> x >> n;
    char ch; cin >> ch;
    for (int i = 0; i < 1000; i++) cout << ch;
    return 0;
}

  

如果说他这个X的条件很大 就得用其他的方法写

#include <bits/stdc++.h>
    
using namespace std; 

int main() {
    ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    int x; cin >> x;//诱惑值
    int n; cin >> n;//个数
    char maxch;
    int maxw; cin >> maxch >> maxw;
    for (int i = 1; i < n; i++) {
        char ch; int w; cin >> ch >> w;
        if (maxw < w) {
            maxch = ch; maxw = w;
        }
    }
    if (maxw * 1000 < x) { 
        cout << -1; 
    }
    else {
        for (int i = 0; i < 1000; i++) {
            cout << maxch;
        }
    }
    return 0;
}

  

 B.人列计算机

思路:

当时卡在与门一直想着相同出1可惜 总共三种情况枚举即可, 根据题目的下方注释即可

Code:

#include <bits/stdc++.h>
    
using namespace std;

string s[12];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    cout << fixed << setprecision(12);
    for (int i = 0; i < 5; i++) {
        getline(cin, s[i]);
    }
    //与门 或门 非门
    // 1-> 与门 & 1 1 出 1 其余出0
    if (s[2][5] ==  '&') {
        if (s[1][0] == s[3][0] && s[1][0] == '1') {
            cout << 1;
        }
        else {
            cout << 0;
        }
    }
    // 2-> 或门 >= 1 只要有1出1 其余0 
    else if (s[2][5] == '=') {
        if (s[1][0] == '1' || s[3][0] == '1') {
            cout << 1;
        }
        else {
            cout << 0;
        }
    }
    // 3-> 非门 0 -> 1 or 1 -> 0
    else {
        if (s[2][0] == '0') {
            cout << 1;
        }
        else {
            cout << 0;
        }
    }
    return 0;
}

  

C.时间管理大师

思路:

很简单,先把时间转换分钟储存map最后输出即可

Code:

#include <bits/stdc++.h>
    
using namespace std; 

int main() {
    ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    cout << fixed << setprecision(12);
    int T; cin >> T;
    map<int, int> mp;
    while (T--) {
        int h, m; cin >> h >> m;
        int sum = h * 60 + m;
        mp[sum - 1] ++; mp[sum - 3]++; mp[sum - 5]++;
    }
    cout << mp.size() << '\n';
    for (auto x : mp) {
        cout << x.first / 60 << ' ' << x.first % 60 << '\n';
    }
    return 0;
}

  

 D.我不是大富翁

思路:

它是环形的 只要判断最后的dp[m][0] == 1即可

他有两个方向一个顺时针一个逆时针 移动 a[i] 距离

所有只要dp一下是否能被其一转移到即可

主要在书写条件时出现了问题

1 (-减) dp[i - 1][(j - x % n + n) % n]

2 (+加) dp[i - 1][(j + x) % n] 即可

Code1:

#include <bits/stdc++.h>
    
using namespace std; 
const int N = 5e3 + 10;

bool dp[N][N] = {true};

int main() {
    ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    cout << fixed << setprecision(12);
    int n, m; cin >> n >> m; 
    for (int i = 1, x; i <= m; i++) {
        cin >> x; x %= n;
        for (int j = 0; j < n; j++) {
            dp[i][j] = dp[i - 1][(j - x + n) % n] | dp[i - 1][(j + x) % n];
        }
    }
    cout << (dp[m][0] ? "YES\n" : "NO\n");
    return 0;
}

  

E.多重映射

思路:

需要逆向想法, 从后往前映射 如果这个r[i] 存在与不存在都需要讲原来的fa[l[i]]的map值覆盖 最后是f[in[i]]存在说明输出这里最终的映射结果或输出原来的值即可

Code:

#include <bits/stdc++.h>
    
using namespace std; 

int main() {
    ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    cout << fixed << setprecision(12);
    int T; cin >> T;
    while (T--) {
        int n, m; cin >> n >> m;
        vector<int> in(n), l(m), r(m);
        map<int, int> fa;
        for (int i = 0; i < n; i++) {
            cin >> in[i];
        } 
        for (int i = 0; i < m; i++) {
            cin >> l[i] >> r[i];
        }
        for (int i = m - 1; i >= 0; i--) {
            if (fa.count(r[i])) {
                fa[l[i]] = fa[r[i]];
            }
            else {
                fa[l[i]] = r[i];
            }
        }
        for (int i = 0; i < n; i++) {
            cout << (fa[in[i]] ? fa[in[i]] : in[i]) << ' ';
        }
        cout << '\n';
    }
    return 0;
}

  

下班明日再补题