http://acm.hdu.edu.cn/showproblem.php?pid=2796
Test instructions: Piles of coin of different sizes.
The condition is that the current heap top size is greater than the current heap of all coin; the top size of the current heap is greater than the top size of the previous heap, and the current heap has a coin number greater than the previous heap.
To find out how many heaps the maximum can be divided.
Idea: To heap the largest, you need to let the top size without heap as small as possible. So the best time is that I heap has I coin, so we construct this situation as much as possible. Finally, put the rest directly to the last heap.
So you need to sort the first and then sweep through the array to determine the condition. Note the top size of the current heap is unique if
#include <stdio.h>#include<string.h>#include<algorithm>using namespacestd;inta[ -],n;intMain () { while(SCANF ("%d", &n)! =EOF) {memset (A,0,sizeof(a)); for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); } sort (A,a+n+1); intk=1; intfro=a[1]; intSite=1; intleft=0; for(intI=2; i<=n;i++){ if(a[i]>fro&&i-site+left>=k+1&&a[i]!=a[i-1]) {fro=A[i]; Left=i-site-k-1+Left ; Site=i; K++; }Else Continue; } printf ("%d\n", k);}return 0;}
Coin piles--hdu2796