Question: How many faces and lateral views can you find, and how many views can be used at least?
Idea: greedy thinking. When we want to minimize the number of views, we can calculate the number of views at different heights and then calculate them, that is, each time the height of the positive view is used to match the maximum value of the lateral view.
# Include <iostream> # include <cstring> # include <cstdio> # include <algorithm> using namespace STD; const int maxn = 1000; int K; int view [2] [maxn]; int main () {int t; scanf ("% d", & T); While (t --) {scanf ("% d", & K); memset (view, 0, sizeof (View); For (INT I = 0; I <2; I ++) for (Int J = 0; j <K; j ++) {int X; scanf ("% d", & X ); view [I] [x] ++;} int min = 0, max = 0; For (INT I = 1; I <maxn; I ++) min + = I * max (view [0] [I], view [1] [I]); For (INT I = 1; I <maxn; I ++) for (Int J = 1; j <maxn; j ++) MAX + = min (I, j) * view [0] [I] * view [1] [J]; printf ("Matty needs at least % d blocks, and can add at most % d extra blocks. \ n ", Min, max-min);} return 0 ;}