京东笔试 0911 C++ AK

竟然全是模拟,没想到俺也能有AK的一天
赶紧做个纪念

键盘输入

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    int n = 0;
    int m = 0;
    cin >> n >> m;

    int x = 0;
    int y = 0;
    int z = 0;
    cin >> x >> y >> z;

    unordered_map<char, pair<int, int>> keys;
    keys.reserve(n*m);

    char last = 0;

    for( int i = 0; i < n; ++i )
    {
        for( int j = 0; j < m; ++j )
        {
            char temp = 0;
            if( i == 0 && j == 0 )
            {
                last = temp;
            }
            cin >> temp;
            keys[temp] = {i, j};
        }
    }

    string str;
    cin >> str;

    ll res = 0;

    for( char& c : str )
    {
        res += abs(keys[last].second - keys[c].second)*x + abs(keys[last].first - keys[c].first)*x;

        if( ! (keys[last].second == keys[c].second or keys[last].first == keys[c].first ) )
        {
            res += y;
        }

        res += z;

        last = c;
    }

    cout << res;

    return 0;
}

systemd

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    int n = 0;
    int q = 0;

    cin >> n >> q;


    unordered_set<int> start_set;
    start_set.reserve(n);

    unordered_set<int> shoutdown_set;
    shoutdown_set.reserve(n);

    unordered_map<int, vector<int>> needed;
    needed.reserve(n);

    unordered_map<int, vector<int>> was_needed;
    was_needed.reserve(n);

    for( int i = 1; i <= n; ++i )
    {
        int c = 0;
        cin >> c;

        needed[i] = vector<int>(c);

        for( int& n : needed[i] )
        {
            cin >> n;
            was_needed[n].push_back(i);
        }

        shoutdown_set.insert(i);

    }

    queue<int> to_start;
    queue<int> to_showtdown;

    int working = 0;

    for( int i = 0; i < q; ++i )
    {
        int type = 0;
        int num = 0;

        cin >> type >> num;

        if( type == 1 )
        {
            if( start_set.count(num) == 1)
            {
                cout << working << endl;
            }
            else
            {
                to_start.push(num);
                while( ! to_start.empty() )
                {
                    int curr_num = to_start.front();
                    to_start.pop();
                    if( start_set.count( curr_num ) == 1 )
                    {
                        continue;
                    }
                    else
                    {
                        start_set.insert(curr_num);
                        shoutdown_set.erase(curr_num);

                        ++ working;
                        // cout << "strat " << curr_num << "  ";

                        for( int& i : needed[curr_num] )
                        {
                            to_start.push(i);
                        }
                    }
                }
                cout << working << endl;
            }
        }
        else
        {
            if( shoutdown_set.count(num) == 1 )
            {
                cout << working << endl;
            }
            else
            {
                to_showtdown.push(num);

                while( ! to_showtdown.empty() )
                {
                    int curr_num = to_showtdown.front();
                    to_showtdown.pop();

                    // cout << "showtdown " << curr_num << "  ";
                    if( shoutdown_set.count(curr_num) == 1 )
                    {
                        continue;
                    }
                    else
                    {
                        shoutdown_set.insert(curr_num);
                        start_set.erase(curr_num);

                        -- working;

                        for( int& i : was_needed[curr_num] )
                        {
                            to_showtdown.push(i);
                        }
                    }
                }

                cout << working << endl;
            }
        }
    }

    return 0;
}
#京东##笔经#
全部评论
老哥 我想问一下 第一题你是做过类似的题吗?主要是想请教一下是怎么想出这种思路的,因为一般来说都会建个图然后进行搜索
点赞
送花
回复
分享
发布于 2021-09-11 21:41
老哥第二题可以说一下是啥思路嘛 我懵了
点赞
送花
回复
分享
发布于 2021-09-12 00:07
网易互娱
校招火热招聘中
官网直投
请问大家做完笔试,官网的状态还是显示未笔试吗?
点赞
送花
回复
分享
发布于 2021-09-12 00:19
请问您说的模拟是啥意思,是有模拟题吗
点赞
送花
回复
分享
发布于 2021-09-12 16:36

相关推荐

1 7 评论
分享
牛客网
牛客企业服务