#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=200+5,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
int cnt[N];
int n,m,x;
int main()
{
scanf("%d",&casenum);
for(casei=1;casei<=casenum;++casei)
{
int ans=0;
MS(cnt,0);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
{
scanf("%d",&x);
++cnt[x];
ans+=x;
}
for(int i=1;i<=m;++i)
{
scanf("%d",&x);
if(cnt[x])--cnt[x];
else ans+=x;
}
printf("%d\n",ans);
}
return 0;
}
/*
【题意】
给你一个积木块的正视图和侧视图,让你输出这个积木块的最小积木数。
这个积木块的长和宽都是[1,200]范围的数。
【类型】
贪心
【分析】
我们只看正视图,积木数肯定至少为正视图的面积
我们只看侧视图,积木数也肯定至少为侧视图的面积
然而,一起看的话,答案却并非是两者之和。
因为,我们是可能存在——
正视图某个横坐标y是一个高度,对应的侧视图的x也是这个高度。
那么,我们就可以只安排一个这样高度的积木在这个交叉位置。从而少一次计数。我们把这个定义重叠
但是,正视图的每列积木,在侧视图上,最多只能起到一次消除。
于是,用一个数组cnt[]对正视图的列做统计,然后在侧视图上对应如果还有,就消除。
可以消除不计数,否则计数。这样就使得我们就做完啦!
【时间复杂度&&优化】
O(n+m)
*/
【2015广东工业大学新生赛I】【贪心】Stubird说这是水题 给定正视图和侧视图求最少积木数
最新推荐文章于 2023-01-15 17:43:56 发布