网易雷火笔试题

#include <iostream>
#include <string>
#include <map>
using namespace std;
map<char, int> getNext(map<char, int>& last, map<char, int>& current) {
    map<char, int> next = current;
    for (auto c : last) {
        next[c.first] += c.second;
    }
    return next;
}

int main() {
    int n = 0;
    string tmp1 = "";
    string tmp2 = "";
    map<char, int> last;
    map<char, int> current;
    map<char, int> next;
    // 本来是用字符串直接算的,思路基本一致,但是会内存超限
    // 所以直接用map存储
    
    cin >> n >> tmp1 >> tmp2;
    for (auto c1 : tmp1) {
        last[c1]++;
    }
    for (auto c2 : tmp2) {
        current[c2]++;
    }
    if (n == 1) next = last;
    if (n == 2) next = current;
    //cout << n << last << current;
    for (int i = 3; i <= n; i++) {
        next = getNext(last, current);
        last = current;
        current = next;
    }
    //cout << next << endl;
    
    for (auto c : next) {
        cout << c.first << ":" << c.second << endl;
    }
    return 0;
}
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, time,res = 0, t = 0;
    int m = 0;
    cin >> n >> time;
    vector<vector<int>> vec(n, vector<int>(2, 0));
    while (t < n) {
        scanf("%d%d", &vec[t][0], &vec[t][1]);
        // 这里m获得最晚跑的的时间
        m = max(m, vec[t][0]);
        t++;
    }
    // 主要的思路都在这个循环里,首先杀怪的个数是可以基本确定的,
    // 即最晚跑的的时间与杀怪时间的比值,这里假定每个时间段time
    // 都会杀一个怪,所以总共循环m+1次,每个怪被杀了就把该位置为-1
    // 这里的tmp既可以得到在某个时间段里,能杀到怪得到的最大经验
    m /= time; //杀掉的怪的个数
    while (m > -1) {
        int tmp = 0;
        for (int i = 0; i < n; i++) {
            if (vec[i][0] >= time*m  && vec[i][0] != -1) {
                tmp = max(tmp, vec[i][1]);
            }
        }
        for (int j = 0; j < n; j++) {
            
            if (tmp == vec[j][1]) {
                if (vec[j][0] >= time*m  && vec[j][0] != -1) {
                    vec[j][0] = -1;
                    break;
                }
                
                
            }
        }
        res += tmp;
        m--;
    }

    cout << res << endl;
    return 0;
}
发布了24 篇原创文章 · 获赞 2 · 访问量 6352

猜你喜欢

转载自blog.csdn.net/Xuesengxinyi/article/details/105182421