标签:uva
题意:有n×n的由边长是1的正方体组成的正视图和侧视图,问此时最少多少个正方体能组成这种正视图和侧视图,还有在最少的基础上最多添加多少个正方体同样形成完全相同的正视图和侧视图。
题解:之前有做过一个类似的题求最少个正方体分析在此,推最多个正方体也很简单,就是先根据一种视图填满每一列,然后根据另一个视图将多填的再减掉就可以了。
#include <stdio.h> #include <string.h> const int N = 10; int a1[N], a2[N], mp[N], n; int main() { int t; scanf("%d", &t); while (t--) { memset(mp, 0, sizeof(mp)); scanf("%d", &n); int sum1 = 0, sum2 = 0; for (int i = 0; i < n; i++) { scanf("%d", &a1[i]); mp[a1[i]]++; sum1 += a1[i]; sum2 += a1[i] * n; } for (int i = 0; i < n; i++) { scanf("%d", &a2[i]); mp[a2[i]]--; for (int j = 0; j < n; j++) if (a1[j] > a2[i]) sum2 -= a1[j] - a2[i]; } for (int i = 0; i < 9; i++) if (mp[i] < 0) sum1 -= (mp[i] * i); printf("Matty needs at least %d blocks, and can add at most %d extra blocks.\n", sum1, sum2 - sum1); } return 0; }
标签:uva
原文地址:http://blog.csdn.net/hyczms/article/details/45208459