#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int cmp(const int &a , const int &b)
{
return a >= b;
}
int cmp1(const int &a , const int &b)
{
if(a%10 == b%10)
{
return a <= b;
}
else
{
return a%10 <= b%10;
}
}
int m, n, n1[35], n2[35], dp[35], res[35];
int main()
{
int t;
cin >> t;
while(t--)
{
cin >> m >> n;
for(int i = 0 ; i < m ; i++) cin >> n1[i];
for(int i = 0 ; i < n ; i++) cin >> n2[i];
sort(n1,n1+m,cmp);
sort(n2,n2+n,cmp);
memset(dp,0,sizeof(dp));
int p1, p2, dppos = 0;
p1 = p2 = 0;
while(p1 < m && p2 < n)
{
if(n1[p1] == n2[p2])
{
p1++;
p2++;
dp[dppos]++;
}
else if(n1[p1] > n2[p2])
{
p1++;
dppos = p1;
}
else
{
p2++;
}
}
int index , maxlen;
maxlen = 0;
for(int i = 0 ; i < min(m,n) ; i++)
{
if(dp[i] > maxlen)
{
index = i;
maxlen = dp[i];
}
}
if(maxlen == 0)
{
printf("NONE\n");
continue;
}
else
{
int pos = 0;
for(int i = index ; i < index+maxlen ; i++)
{
if(i == 0) res[pos++] = n1[i];
else
{
//重复不记
if(n1[i] != n1[i-1]) res[pos++] = n1[i];
}
}
for(int i = 0 ; i <= pos-1 ; i++)
printf("%d ",res[i]);
printf("\n");
sort(res,res+pos,cmp1);
for(int i = 0 ; i <= pos-1 ; i++)
printf("%d ",res[i]);
printf("\n");
}
}
return 0;
}
POJ4044 A Score Sequence
最新推荐文章于 2020-08-10 13:56:42 发布