题意
给出正视图和侧视图,判断最少用几个立方体
分析
若存在高度相同的立方块,则以数目多的那面为准。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = ; int num1[MAXN],num2[MAXN];
int n,m; int main(){
while (scanf("%d%d",&m,&n) != EOF && n+m){
memset(num1,,sizeof(num1));
memset(num2,,sizeof(num2));
int x;
for (int i = ; i < m; i++){
scanf("%d",&x);
num1[x]++;
}
for (int i = ; i < n; i++){
scanf("%d",&x);
num2[x]++;
}
int ans = ;
for (int i = ; i < ; i++)
ans += i*max(num1[i],num2[i]);
printf("%d\n",ans);
}
return ;
}
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- const int MAXN = 30;
- int num1[MAXN],num2[MAXN];
- int n,m;
- int main(){
- while (scanf("%d%d",&m,&n) != EOF && n+m){
- memset(num1,0,sizeof(num1));
- memset(num2,0,sizeof(num2));
- int x;
- for (int i = 0; i < m; i++){
- scanf("%d",&x);
- num1[x]++;
- }
- for (int i = 0; i < n; i++){
- scanf("%d",&x);
- num2[x]++;
- }
- int ans = 0;
- for (int i = 1; i < 25; i++)
- ans += i*max(num1[i],num2[i]);
- printf("%d\n",ans);
- }
- return 0;
- }