Uva434 logic (logical)
Question: There are n × n positive and lateral views composed of cubes with a side length of 1. Ask how many squares can constitute the front view and lateral view at this time, the number of cubes that can be added at most is the same as the number of cubes that can be added to form the same forward and lateral views.
Question: I have done a similar question before to find at least cube analysis here. It is very easy to push at most cubes, that is, to fill each column according to a view first, then, based on the other view, you can reduce the overfilled value.
# 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 ;}