CSU 1578 Opening ceremony (recursive)

Source: Internet
Author: User

Test instructions: There is a row of n buildings each high uncertainty now to eliminate all buildings

There are two ways to eliminate all blocks with a value of 1.

2 elimination of an entire building

Ask how to eliminate it with minimal steps

Idea: First sort the array from large to small

     if (I+a[i]<ans) ans=i+a[i];

#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int a[1000000+100];int CMP (int a,int b) {    return a>b;} int main () {    int n;    int i,j,k;    while (scanf ("%d", &n)!=eof)    {        int ans;        for (i=0;i<n;i++) scanf ("%d", &a[i]);        Sort (a,a+n,cmp);        ANS=A[0];        printf ("%d\n", ans);        for (i=1;i<n;i++)        {            if (I+a[i]<ans) ans=i+a[i];        }        if (ans>n) ans=n;        printf ("%d\n", ans);    }    return 0;}

  

CSU 1578 Opening ceremony (recursive)

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.