1085. Perfect Sequence (25)
2015-09-08 22:17
459 查看
题目链接:http://www.patest.cn/contests/pat-a-practise/1085
题目:
Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M <= m * p where M and m are the maximum and minimum numbers in the sequence, respectively.
Now given a sequence and a parameter p, you are supposed to find from the sequence as many numbers as possible to form a perfect subsequence.
Input Specification:
Each input file contains one test case. For each case, the first line contains two positive integers N and p, where N (<= 105) is the number of integers in the sequence, and p (<= 109) is the
parameter. In the second line there are N positive integers, each is no greater than 109.
Output Specification:
For each test case, print in one line the maximum number of integers that can be chosen to form a perfect subsequence.
Sample Input:
Sample Output:
分析:
第一个给出一个数目和一个参数,要求输出满足条件的组成满足条件的最多的数量
比如10和8中,在第二个数组中只有当20和1都去除的时候,得到最多的8个数组成“完美数列”
所以我们先对数组进行一下排序,然后按照从小到达统计出所有可能的情况,找出最大的数量值
参考了:http://blog.csdn.net/nan327347465/article/details/39104721
上面说到long long,改后就好了,另外上面还说到二分查找,我这里用了不同的方法。
证明了测试点5是用非常大的用到了long long。
测试点4应该是数据量很大的。
AC代码:
截图:
![](http://img.blog.csdn.net/20150908221705002?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
——Apie陈小旭
题目:
Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M <= m * p where M and m are the maximum and minimum numbers in the sequence, respectively.
Now given a sequence and a parameter p, you are supposed to find from the sequence as many numbers as possible to form a perfect subsequence.
Input Specification:
Each input file contains one test case. For each case, the first line contains two positive integers N and p, where N (<= 105) is the number of integers in the sequence, and p (<= 109) is the
parameter. In the second line there are N positive integers, each is no greater than 109.
Output Specification:
For each test case, print in one line the maximum number of integers that can be chosen to form a perfect subsequence.
Sample Input:
10 8 2 3 20 4 5 1 6 7 8 9
Sample Output:
8
分析:
第一个给出一个数目和一个参数,要求输出满足条件的组成满足条件的最多的数量
比如10和8中,在第二个数组中只有当20和1都去除的时候,得到最多的8个数组成“完美数列”
所以我们先对数组进行一下排序,然后按照从小到达统计出所有可能的情况,找出最大的数量值
参考了:http://blog.csdn.net/nan327347465/article/details/39104721
上面说到long long,改后就好了,另外上面还说到二分查找,我这里用了不同的方法。
证明了测试点5是用非常大的用到了long long。
测试点4应该是数据量很大的。
AC代码:
#include<stdio.h> #include<iostream> #include<string> #include<vector> #include<algorithm> #include<string.h> using namespace std; int main(){ freopen("F://Temp/input.txt", "r", stdin); int N, p; cin >> N >> p; long long *input = new long long ; for (int i = 0; i < N; ++i){ cin >> input[i]; } sort(input, input + N);//排序 int max = 1; int cur_count = 2; int idx_t = 1; int idx_s = 0; for (; idx_s < N - 1; ++idx_s){ --cur_count; for (; idx_t < N; ++idx_t){ if (input[idx_t] <= input[idx_s] * p) ++cur_count; else{ break; } } if (cur_count > max)max = cur_count; } cout << max << endl; return 0; }
截图:
——Apie陈小旭
相关文章推荐
- iOS——UINavigationController
- iOS:带主标题、副标题、图像类型的表格视图UITableView
- mysql mysqldmin 命令行工具 GUI工具
- UISwitch / UIStepper
- IOS子UITabBarController效果
- /res/values-navexposed 然并卵
- rejected execution (queue capacity 50)
- codeforces 172B B. Pseudorandom Sequence Period(暴力)
- UI中的隐藏键盘的三个小方法
- IOS动画中的枚举UIViewAnimationOptions
- hdu 4296 Buildings(贪心)
- hdu1297 Children’s Queue
- UIday1103:UITableView 3 cell高度自适应代码
- POJ 1122 FDNY to the Rescue!
- Handler 机制学习之Handler、Looper、MessageQueue、Message之间的关系
- UIday1102:UITabelView 3 cell的混合使用代码举例
- UVA 11324 The Largest Clique(tarjan有向图强连通+缩点)
- UIday1101:UITableView 3 自定义cell 多种cell混合使用 cell自适应高度
- Permutation Sequence
- 【postgresql】创建自增SEQUENCE