1085 Perfect Sequence (25分)

查看其它博客的方法,發現還有個distance方法 

distance (InputIterator first, InputIterator last); 在c++中,distance爲一函數模版,返回兩個迭代器間的距離。

 

 

#include<iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
	ll n, p, t, tmp;
	
	scanf("%lld%lld", &n, &p);
	ll v[n];
	for (ll i = 0; i < n; ++i) {
		scanf("%lld", &tmp);
		v[i] = tmp;
	}
	
	sort(v, v+n);
	int ans = 0;
	
	for (int i = 0; i < n; ++i) {
		t = p * v[i];
		int tmp = upper_bound(v, v+n, t)-v-i;
	
		ans = max(ans, tmp);
	}
	
	printf("%d\n", ans);
	
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章