Coin piles--hdu2796

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.