Perfect series "pinned"

Source: Internet
Author: User
Tags cmath

Links: Http://www.nowcoder.com/questionTerminal/5bed191944ce4eaa93f4bae50abc90df

Title Description
Given a positive integer sequence, and a positive integer p, the maximum value in this sequence is m, the minimum is m, and if M <= m * p, then this sequence is called the perfect sequence.



Now given the parameter p and some positive integers, you can choose as many numbers as possible to make a perfect sequence.

Input Description:
Enter the first line to give two positive integers n and p, where N (<= 105) is the number of positive integers entered, and P (<= 109) is the given parameter. The second line gives n positive integers, each of which

No more than 109.



Output Description:
You can select the maximum number of rows in a row to make a perfect sequence.

Input Example:
10 8

2 3 20 4 5 1 6 7 8 9

Output Example:
8

Train of thought: test instructions is very simple, but really need to consider the efficiency of the words also needs to think of ways. AC code is looked at others, the idea is very good, earnest study!
1 AC Code:2#include"iostream"3#include <cstdio>4#include <string.h>5#include <string>6#include <cmath>7#include <algorithm>8 using namespacestd;9  Ten Const intMAXN =100005; One intNUM[MAXN]; A   -   - intMain () the { -     intN, p, I, J; -scanf"%d%d", &n, &p); -      for(i=1; i<=n; ++i) +     { -scanf"%d", &num[i]); +     } ASort (num+1, num+n+1); at     intlen=0, flag=0; -      for(intI=1; i<=n; ++i) -     { -          for(intJ=i+len; j<=n; ++j) -         { -             if(Num[j] > num[i]*p) in             { -                  Break;  to             } +             if(j-i+1>len) -             { theLen = j-i+1;  *             } $         }Panax Notoginseng     } -cout <<len <<Endl; the     return 0; +}
1 tle Code:2#include"iostream"3#include <iomanip>4#include <string.h>5#include <string>6#include <vector>7#include <cmath>8#include <cctype>9#include <algorithm>Ten using namespacestd; One  A Const intMAXN =100005; - intNUM[MAXN]; -  the intMain () - { -     intN, p, I, J; -     //cin >>n >>p; +scanf"%d%d", &n, &p); -      for(i=1; i<=n; ++i) +     { A         //Cin >>num[i]; atscanf"%d", &num[i]); -     } -Sort (num+1, num+n+1); -     intlen=0, flag=0; -      for(intI=n; i>=1; --i) -     { in          for(intj=1; j<=n-i+1; ++j) -         { to             if(num[j+i-1] <= p*Num[j]) +             { -Len =i; theFlag =1; *                  Break; $             }Panax Notoginseng         } -         if(Flag = =1) the         { +              Break; A         } the     } +cout <<len <<Endl; -     return 0; $}

Perfect series "pinned"

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.