网易2019实习生招聘题解

个人解答,不代表官方做法。

详细题解:请移步网易2019实习生招聘编程题集合 - 题解https://blog.csdn.net/flushhip/article/details/79721659

GitHub:网易2019实习生招聘编程题集合

代码如下:

// 1
#include <bits/stdc++.h>

using namespace std;

int main()
{
    for (int n, m; cin >> n >> m; ) {
        vector<pair<int, int> > arr;
        for (int i = 0, d, p; i < n; cin >> d >> p, arr.emplace_back(d, p), i++) {}
        sort(arr.begin(), arr.end());
        vector<int> ans(n);
        ans[0] = arr[0].second;
        for (int i = 1; i < (int)arr.size(); ans[i] = max(ans[i - 1], arr[i].second), ++i) {}

        for (int x; m--; ) {
            cin >> x;
            cout << ans[upper_bound(arr.begin(), arr.end(), make_pair(x, 0x3f3f3f3f)) - 1 - arr.begin()] << endl;
        }
    }
    return 0;
}
// 2
#include <bits/stdc++.h>

using namespace std;

int fun(int x)
{
    return x / 3 * 2 + (x % 3 == 0 ? 0 : x % 3 == 1 ? 0 : 1);
}

int main()
{
    for (int l, r; cin >> l >> r; cout << fun(r) - fun(l - 1) << endl) {}
    return 0;
}

// 3
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int T;
    for (cin >> T; T--; ) {
        int n, ans = 0;
        string str;
        cin >> n >> str;
        for (int i = 0; i < (int)str.size(); ) {
            for (; i < (int)str.size() && str[i] == 'X'; ++i) {}
            for (; i < (int)str.size() && str[i] == '.'; ans++, i += 3) {}
        }
        cout << ans << endl;
    }
    return 0;
}

// 4
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
    for (LL n, k; cin >> n >> k; ) {
        LL ans = 0;
        if (!k)
            ans = n * n;
        else
            for (LL y = k + 1; y <= n; y++)
                ans += n / y * (y - k) + (n % y >= k ? n % y - k + 1 : 0);
        cout << ans << endl;
    }
    return 0;
}

// 5
#include <bits/stdc++.h>

using namespace std;

struct Rect {
    int x[4];
    Rect() {}
};

bool judge(const vector<Rect>::iterator &it, int x, int y)
{
    return it->x[0] < x && x < it->x[2] && it->x[1] < y && y < it->x[3];
}

int main()
{
    for (int n; cin >> n; ) {
        vector<Rect> rects(n);
        vector<int> approch_x, approch_y;
        for (int i = 0, x; i < n; cin >> x, approch_x.push_back(rects[i++].x[0] = x)) {}
        for (int i = 0, x; i < n; cin >> x, approch_y.push_back(rects[i++].x[1] = x)) {}
        for (int i = 0, x; i < n; cin >> x, approch_x.push_back(rects[i++].x[2] = x)) {}
        for (int i = 0, x; i < n; cin >> x, approch_y.push_back(rects[i++].x[3] = x)) {}
        sort(approch_x.begin(), approch_x.end());
        sort(approch_y.begin(), approch_y.end());
        for (auto it = rects.begin(); it != rects.end(); ++it) {
            for (int i = 0; i < 4; i++) {
                if (i % 2 == 0)
                    it->x[i] = (lower_bound(approch_x.begin(), approch_x.end(), it->x[i]) - approch_x.begin()) * 2;
                else
                    it->x[i] = (lower_bound(approch_y.begin(), approch_y.end(), it->x[i]) - approch_y.begin()) * 2;
            }
        }

        int col = (lower_bound(approch_x.begin(), approch_x.end(), approch_x.back()) - approch_x.begin()) * 2;
        int row = (lower_bound(approch_y.begin(), approch_y.end(), approch_y.back()) - approch_y.begin()) * 2;

        int ans = 1;
        for (int i = 0; i + 2 < row; i += 2) {
            for (int j = 0; j + 2 < col; j += 2) {
                int sum = 0;
                for (auto it = rects.begin(); it != rects.end(); ++it)
                    sum += judge(it, i + 1, j + 1);
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

// 6
#include <bits/stdc++.h>

using namespace std;

int main()
{
    const char DIR[] = "NESW";
    for (int n; cin >> n; ) {
        string str;
        cin >> str;
        int ans = 0;
        for (int i = 0; i < n; i++)
            ans = (ans + (str[i] == 'L' ? -1 : 1) + 4) % 4;
        cout << DIR[ans % 4] << endl;
    }
    return 0;
}

// 7
#include <bits/stdc++.h>

using namespace std;

int main()
{
    for (int n; cin >> n; ) {
        vector<int> arr;
        for (int i = 0, x, y; i < n; cin >> x >> y, arr.push_back(x * 60 + y), ++i) {}
        sort(arr.begin(), arr.end());
        int x, A, B;
        cin >> x >> A >> B;
        int ans = *(lower_bound(arr.begin(), arr.end(), A * 60 + B - x + 1) - 1);
        cout << ans / 60 << " " << ans % 60 << endl;
    }
    return 0;
}

// 8
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()
{
    for (LL n, w; cin >> n >> w; ) {
        vector<LL> v;
        for (int i = 0, x; i < n; cin >> x, v.push_back(x), ++i) {}

        LL n1 = n >> 1, n2 = n - n1;

        vector<LL> arr;
        for (int i = 0; i < (1 << n1); i++) {
            LL sum = 0;
            for (int bits = 0; bits < n1; bits++)
                sum += (i & (1 << bits)) ? v[bits] : 0;
            arr.push_back(sum);
        }
        sort(arr.begin(), arr.end());

        LL ans = 0;
        for (int i = 0; i < (1 << n2); i++) {
            LL sum = 0;
            for (int bits = 0; bits < n2; bits++)
                sum += (i & (1 << bits)) ? v[n1 + bits] : 0;
            ans += lower_bound(arr.begin(), arr.end(), w - sum + 1) - arr.begin();
        }
        cout << ans << endl;
    }
    return 0;
}
#实习##网易##笔试题目#
全部评论
笔试结果出来了没
点赞 回复 分享
发布于 2018-03-29 20:56

相关推荐

冷艳的小师弟在看机会:jd测评乱点直接被挂了,哭死~
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务