题意:求最多可以组多少对舞伴,每对舞伴的技能数差不能大于1. 向左贪心即可
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
const int MAXN = 2e6+5;
int n,m,flag,flag1,ma,mi,ans,sum,T,k,x,y;
int a[MAXN],b[MAXN],dp[MAXN];
char c[MAXN];
int mapp[5001][5001];
string str,str1,str2;
set<char> ss;
vector<int> v[4];
map<string,int> M;
bool judge(int x){if(x==2||x==3)return false;for(int i=2;i<=sqrt(x);i++){if(x%i==0)return true;}return false;}
int gcd(int a,int b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
int main()
{
cin>>n;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=0;i<n;i++)
{
cin>>k;
a[k]++;
}
cin>>m;
for(int i=0;i<m;i++)
{
cin>>k;
b[k]++;
}
//sort(a,a+n);
//sort(b,b+m);
flag=0;
for(int i=1;i<=100;i++)
{
if(a[i]!=0)
{
if(b[i-1]!=0)
{
flag++;
b[i-1]--;
a[i]--;
i--;
continue;
}
if(b[i]!=0)
{
flag++;
b[i]--;
a[i]--;
i--;
continue;
}
if(b[i+1]!=0)
{
flag++;
b[i+1]--;
a[i]--;
i--;
continue;
}
}
}
cout<<flag<<endl;
return 0;
}