CF1453A题解

· · 题解

思路:

这道红题没有涉及到什么难的算法,就是朴素的模拟

根据题意,依次枚举往上往右开的车,其实就是求两个数列中重复的数字的个数

code

#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int t, n, m;
int a[maxn], b[maxn];
int main()
{
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
      cin >> a[i];
    for(int i = 1; i <= m; i++)
      cin >> b[i];
    int ans = 0;
    for(int i = 1; i <= n; i++)
      for(int j = 1; j <= m; j++)
        if(a[i] == b[j])
          ans++;
    cout << ans << endl;
  }
  return 0;
}

不要Ctrl c啊!(就算要,也得先看懂吧QWQ)

完结撒花~