题解:P17329 【12-X】人造战车

· · 题解

可以注意到,题目的数据范围非常小,于是可以直接暴力求解。

代码:

#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> ma;
signed main() {
    int n, m;
    cin >> n >> m;
    string s[1001], t[1001];
    bool vis[1001] = {};
    for (int i = 1; i <= n; i++) {
        cin >> s[i];
        ma[s[i]]++;
    }
    for (int i = 1; i <= m; i++) {
        cin >> t[i];
    }
    for (int i = 1; i <= n; i++) {
        if (ma[s[i]] >= 2) {
            vis[i] = true;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i].find(t[j]) != string::npos) {
                vis[i] = true;
                break;
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (vis[i]) {
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}