Nine degree title 1394: Five Combo array

Source: Internet
Author: User

Reprint please indicate this article link http://blog.csdn.net/yangnanhai93/article/details/40506571

Title Link: http://ac.jobdu.com/problem.php?pid=1394


Problem Analysis:

This problem is a four-star problem, but it feels a little too simple.

The first message to us is that it needs to be sequential, so we'll definitely sort the original array, and then we'll find out how many are missing. This topic to think will find and find the biggest stock in n days the problem is a bit similar, that is, I only care about my current number, look ahead, I now have a few count, and then know how many

So the idea is naturally smooth, moving forward from that number until the number above the current number is greater than or equal to 5.

#include <stdio.h> #include <algorithm>using namespace Std;int main () {//freopen ("data.in", "R", stdin);    int N,a[1000],result;    Short b[1000];        while (scanf ("%d", &n)!=eof) {result=5;            for (int i=0;i<n;i++) {scanf ("%d", &a[i]);        b[i]=0;        } sort (a,a+n);            for (int i=0;i<n;i++) {int j=i;                while (j>=0&&a[i]-a[j]<5) {b[i]++;            j--;            } if (5-b[i]<result) result=5-b[i];        if (result==0) break;    } printf ("%d\n", result); } return 0;}    /************************************************************** problem:1394 User:vincent_ynh language:c++ result:accepted time:0 Ms memory:1020 kb****************************************************************/


Nine degree title 1394: Five Combo array

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.