9.18雷火笔试
1、车牌号直接模拟就好 100%
#include <bits/stdc++.h> using namespace std; int main(){ int T; cin >> T; double ret = 0; int t = T; while(T-- > 0){ int cur_score = 0; string scan, gt; cin >> scan >> gt; vector<string> scan_v; vector<string> gt_v; // 颜色 scan_v.push_back(scan.substr(0, 1)); gt_v.push_back(gt.substr(0, 1)); // 地址 scan_v.push_back(scan.substr(1, scan.size()-1-5)); gt_v.push_back(gt.substr(1, gt.size()-1-5)); // 车牌号 scan_v.push_back(scan.substr(scan.size()-5, 5)); gt_v.push_back(gt.substr(gt.size()-5, 5)); if(scan_v[0] == gt_v[0]) cur_score += 2; if(scan_v[1] == gt_v[1]) cur_score += 3; int same_size = 0; for(int idx1=0; idx1< scan_v[2].size(); idx1++){ for(int idx2=0; idx2< gt_v[2].size(); idx2++){ int len = 0; int i = idx1, j=idx2; while(i< scan_v[2].size()&& j< gt_v[2].size() && scan_v[2][i] == gt_v[2][j]){ i++; j++; len++; } same_size = max(len, same_size); } } cur_score += same_size; ret += ((double)cur_score/10); } ret = ret / (t); printf("%0.2f", ret); return 0; }2、给每一个资源设置一个引用计数,被加载时就加一,减少时就减一,类似shared_ptr 100%
#include <bits/stdc++.h> using namespace std; int cur_size = 0; void load(unordered_set<int>& has_load, vector<vector<int>>& need, vector<int>& times, int id){ if(has_load.find(id) != has_load.end()) return; has_load.insert(id); times[id] += 1; if(times[id] == 1) cur_size += 1; for(int i=0; i< need[id].size(); i++){ load(has_load, need, times, need[id][i]); } } int main(){ int N, M; cin >> N >> M; vector<vector<int>> need(N); vector<int> times(N, 0); for(int i=0; i< N; i++){ int num; cin >> num; int idx = 0; need[i].resize(num); while(num-- > 0){ cin >> need[i][idx++]; } } int ret = 0; while(M-- > 0){ int op, id; cin >> op >> id; if(op == 0){ for(int i=0; i< need[id].size(); i++){ times[need[id][i]] -= 1; if(times[need[id][i]] == 0){ cur_size -= 1; } } times[id] -= 1; if(times[id] == 0){ cur_size -= 1; } }else{ unordered_set<int> has_load; load(has_load, need, times, id); } ret = max(ret, cur_size); } cout << ret; return 0; }3、N个矩形求拐点;不会
4、10张地图,每张地图有怪,和金币,求自身能获得的最大金币数量;不会