Question A:
Greedy water problem, pay attention to this group of data, pit a lot of people
Question B:
Sort the array first, and then the problem can be abstracted to find the maximum number of ascending sub-sequences of an ordered array, and the implementation is a bit clumsy (I'd rather call it ingenious:))
#include <iostream> #include <cstring> #include <algorithm> #define INF 99999using namespace Std;int Num[1007][1007];int Main () {int n;int a[1007];while (cin>>n) {int ans = 0;memset (num,0,sizeof (num)); for (int i = 1;i & lt;= n;i++) Cin>>a[i];sort (a+1,a+1+n);//Initialize first int cnt = 0;int Min = inf;num[1][++cnt]++;int tmp = a[1];for (int i = 2 ; I <= n;i++) {if (a[i] = = tmp) num[1][cnt]++;else {tmp = a[i];num[1][++cnt]++;}} for (int i = 1;i <= cnt;i++) min = min (min,num[1][i]), int y = 1;while (cnt) {ans + = (cnt-1) *min;int tcount = 0;for (int i = 1;i <= cnt;i++) {num[y][i]-= Min;if (Num[y][i]) num[y+1][++tcount] = Num[y][i];} CNT = tcount;y++; min = inf;for (int i = 1;i <= cnt;i++) min = min (min,num[y][i]);} Cout<<ans<<endl;} return 0;}
Question C:
The calculation formula of the two can be deduced to find any two points to meet the requirements, as long as xy two coordinates as long as the (x| | Y) The compound proposition is true. Then as for the size of the array, here reference a special data structure to store a large amount of data, and then note that x or Y coordinates have the same n points, and ans is to add or subtract n (n-1)/2
cf#345 Div2 a\b\c problem