FlowerAccepted @ 2024-11-13 18:22:59
如题,求条。 代码如下:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
long long a[500005], b[500005];
int main() {
int n, m, ans = 0, cnt = 0;
cin >> n >> m;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
}
for (int i = 1; i <= m; i ++) {
cin >> b[i];
}
sort(a + 1, a + n + 1);
sort(b + 1, b + n + 1);
for (int i = 1; i <= n; i ++, cnt ++) {
if (b[lower_bound(b + 1, b + n + 1, a[i]) - b] == a[i]) {
if (cnt) {
ans ++;
}
cnt = -1;
}
}
if (cnt) {
ans ++;
}
cout << ans;
return 0;
}
by malinhao45 @ 2024-11-21 20:02:25
sort(b + 1, b + n + 1);
这句话改成
sort(b + 1, b + m + 1);
by FlowerAccepted @ 2024-12-04 18:05:47
@malinhao45TYSM..
by FlowerAccepted @ 2024-12-04 18:08:25
@malinhao45还是错的。。。。
by FlowerAccepted @ 2024-12-06 20:53:47
问题解决,原因: sort(a + 1, a + n + 1);
与 n m
请看到这里的管理锁帖。