标签:
贪心,尽量向前配
#include <bits/stdc++.h> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define ForkD(i,k,n) for(int i=n;i>=k;i--) #define MAXN (2000) #define eps (1e-6) int T,a[MAXN],b[MAXN]; int main() { // freopen("H.in","r",stdin); cin>>T; For(kcase,T) { int n; scanf("%d",&n); For(i,n) scanf("%d",&a[i]); sort(a+1,a+1+n); int m; scanf("%d",&m); For(i,m) scanf("%d",&b[i]); sort(b+1,b+m+1); int j=1,ans=0; For(i,n) { while (j<=m&&a[i]+1>=b[j]) { if (abs(a[i]-b[j])<=1) { ans++;j++; break; } j++; } if (j>m) break; } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://blog.csdn.net/nike0good/article/details/45219517