京东笔试 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; }#京东##笔经#