1030. Perfect series (25)

Source: Internet
Author: User

TIPS: The Chinese problem is the basic level of Pat, neverthless and it makes sense that it is

Put under the Dir of Pat.

/*firstly: sort the array using the algorithm "sort"secondly: traverse all the possible answer and find the most suitable one.*/#include<iostream>#include<vector>#include<algorithm>using namespace std;int main(){    long long int n,p;    vector<long long int> v;    while (cin>>n>>p)    {        long long int temp;        while (n--)        {            cin>>temp;            v.push_back(temp);        }        sort(v.begin(),v.end());        long long int max = -1;        for (int i = 0; i < v.size(); i++)        {            long long int count = 1;            for (int j = i + 1; j < v.size(); j++)            {                if (v[i] * p >= v[j])                    count += 1;                else break;            }            if (count >= max)            {                max = count ;            }        }        cout<<max<<endl;    }}

And I'm very sorry that one example is time running out. Maybe there are some parts

Code which can be optimized, however I think it can be left to my reader.

1030. Perfect series (25)

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.