码迷,mamicode.com
首页 > 其他好文 > 详细

1030. 完美数列(25)

时间:2014-09-12 11:50:03      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   art   div   

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 of

code which can be optimized ,however i think it can be left to my reader.

1030. 完美数列(25)

标签:style   blog   color   io   os   ar   for   art   div   

原文地址:http://www.cnblogs.com/maverick-fu/p/3968011.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!