题意:

输入两个正整数N和P(N<=1e5,P<=1e9),接着输入N个正整数。输出一组数的最大个数使得其中最大的数不超过最小的数P倍。

trick:

测试点5会爆int,因为P太大了。。。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
long long val;
bool flag;
};
bool cmp(node a,node b){
if(a.val!=b.val)
return a.val<b.val;
return a.flag>b.flag;
}
node a[];
map<int,int>pos;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,p;
cin>>n>>p;
for(int i=;i<=n;++i)
cin>>a[i].val;
for(int i=;i<=n;++i){
a[i+n].val=a[i].val*p+;
a[i+n].flag=;
}
sort(a+,a++n+n,cmp);
int cnt=;
int ans=;
for(int i=;i<=n+n;++i){
if(a[i].flag==){
++cnt;
if(!pos[a[i].val])
pos[a[i].val]=cnt;
}
else{
int x=(a[i].val-)/p;
int tamp=cnt-pos[x]+;
ans=max(ans,tamp);
}
}
cout<<ans;
return ;
}

【PAT甲级】1085 Perfect Sequence (25 分)的更多相关文章

  1. PAT Advanced 1085 Perfect Sequence (25) [⼆分,two pointers]

    题目 Given a sequence of positive integers and another positive integer p. The sequence is said to be ...

  2. PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

    1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ord ...

  3. PAT 甲级 1085 Perfect Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...

  4. 1085 Perfect Sequence (25 分)

    Given a sequence of positive integers and another positive integer p. The sequence is said to be a p ...

  5. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  6. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  7. PAT 甲级 1020 Tree Traversals (25 分)(二叉树已知后序和中序建树求层序)

    1020 Tree Traversals (25 分)   Suppose that all the keys in a binary tree are distinct positive integ ...

  8. 1085. Perfect Sequence (25) -二分查找

    题目如下: Given a sequence of positive integers and another positive integer p. The sequence is said to ...

  9. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

随机推荐

  1. Centos7添加软链接

    1.pycharm添加软连接: 命令行模式中输入命令: ln -s /root/pycharm-2018.1/bin/pycharm.sh /usr/bin/pycharm ps:代码中/root/p ...

  2. [CF]Round511

    这场比赛我及时的参加了,但是打的时候状态实在是太烂了,只做出来了Div2的AB题. A Little C loves 3 I 直接构造就行. B Cover Points 应该很容易就看出来这个等腰三 ...

  3. java基础之 变量

    变量是一个内存位置的名称. 1.成员变量(实例变量,属性) 成员变量就是类中的属性,当创建对象的时候,每个对象都有一份属性.一个对象中的属性就是成员变量. 2.本地变量(局部变量) 在方法内声明的变量 ...

  4. IntelliJ IDEA 2017.3尚硅谷-----取消更新

  5. MySql5.6表操作

    MySql5.6表操作 数据类型 整型 浮点型 字符类型 日期类型 枚举类型与集合类型 约束条件 Primary key Unique key Not null Foreign key 创建表的完整语 ...

  6. js中float失精

    https://juejin.im/post/5aa1395c6fb9a028df223516 把小数转为整数,然后计算 https://www.html.cn/archives/7340

  7. 题解【POJ2155】Matrix

    Description Given an \(N \times N\) matrix \(A\), whose elements are either \(0\) or \(1\). \(A[i, j ...

  8. 微服务监控平台获取网关(zuul)配置列表

    步骤: (1)读取zuul的配置文件,获取路由配置项信息: private static Properties props; static { String fileName = "appl ...

  9. 事务:Transaction详解

    1.事务概念: 一组sql语句操作单元,组内所有SQL语句完成一个业务,如果整组成功:意味着全部SQL都实现:如果其中任何一个失败,意味着整个操作都失败.失败,意味着整个过程都是没有意义的.应该是数据 ...

  10. 查询 keystore文件的签名信息

    需要安装jdk 在安装 jdk的/bin文件夹下 keytool -v -list -keystore [keystore文件的路径]