PAT (Advanced Level) Practice 1085 Perfect Sequence (25 分)
子序列而非連續子序列,雙指標,列舉最大值,然後l指標不斷往左移
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int a[N];
int main()
{
int n,p;
scanf("%d%d",&n,&p);
for(int i=0;i<n;i++)
scanf("%d",a+i);
sort(a,a+n);
int l=n-1,ans=0;;
for(int i=n-1;i>=0;i--)
{
while(l>=0&&1LL*a[l]*p>=a[i]) l--;
ans=max(ans,i-l);
}
printf("%d\n",ans);
return 0;
}
相關推薦
PAT (Advanced Level) Practice 1085 Perfect Sequence (25 分)
子序列而非連續子序列,雙指標,列舉最大值,然後l指標不斷往左移 #include<cstdio> #include<algorithm> using namespace std; const int N=1e5+5; int a[N]; int main
PAT (Advanced Level) Practice 1114 Family Property (25 分)
程式設計題 1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned property. Given each per
PAT (Advanced Level) Practice 1126 Eulerian Path (25 分)
In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which
PAT (Advanced Level) Practice 1134 Vertex Cover (25 分) set
1134 Vertex Cover (25 分) A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the s
PAT (Advanced Level) Practice 1138 Postorder Traversal (25 分) 樹的重構
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to out
PAT (Advanced Level) Practice 1083 List Grades (25 分)
#include<cstdio> #include<algorithm> #include<vector> using namespace std; const int N=1e3+5; struct People { char name[
PAT (Advanced Level) Practice 1122 Hamiltonian Cycle (25 分)
智障錯誤調了我一天- =,a的大小可能超過N,導致陣列越界,wa最後一個樣例。 #include<cstdio> #include<cstring> #include<map> #include<vector> using namesp
PAT (Advanced Level) Practice 1121 Damn Single (25 分)
#include<cstdio> #include<map> #include<algorithm> #include<vector> using namespace std; const int N=5e4+5; int a[N],v
PAT (Advanced Level) Practice 1117 Eddington Number (25 分)
二分 #include<cstdio> using namespace std; const int N=1e5+5; int n,a[N]; int check(int x) { int num=0; for(int i=1;i<=n;i++
PAT (Advanced Level) Practice 1109 Group Photo (25 分)
模擬,高的且字典序小的排前面,一排排模擬下去即可。 #include<cstdio> #include<cstring> #include<algorithm> #include<string> using namespace std;
PAT (Advanced Level) Practice 1105 Spiral Matrix (25 分)
#include<cstdio> #include<algorithm> #include<cmath> using namespace std; const int N=1e5+5; int a[N],mp[1000+5][1000+5]; i
PAT (Advanced Level) Practice 1021 Deepest Root (25 分)
A graph which is connected and acyclic can be considered a tree. The hight of the tree depends on the selected root. Now you are supposed
PAT (Advanced Level) Practice 1024 Palindromic Number (25 分)大數模擬
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number
PAT (Advanced Level) Practice 1037 Magic Coupon (25 分)
The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a produc
PAT (Advanced Level) Practice 1138 Postorder Traversal (25 分) 樹的重構
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are sup
PAT (Advanced Level) Practice 1126 Eulerian Path (25 分)
In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian
PAT (Advanced Level) Practice 1134 Vertex Cover (25 分) set
1134 Vertex Cover (25 分) A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vert
PAT (Advanced Level) Practice 1020 Tree Traversals (25 分)
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are su
PAT (Advanced Level) Practice 1146 Topological Order (25 分) 拓撲排序
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given d
PAT (Advanced Level) Practice 1142 Maximal Clique (25 分) 暴力
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique