题意:

输入两个正整数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. 执行PDB的PITR恢复失败的说明

    Oracle 12.1版本中,UNDO表空间仅存在CDB级别(共享UNDO),来自于AskScuti博客园. Oracle 12.2版本开始,UNDO表空间同时可以存在每个PDB级别(本地UNDO). ...

  2. 基于.NET Core winform的录音、字幕软件HTWCore的技术总结

    HTWCore是一款基于.NET Core的winform客户端程序,可以用来处理各种会议,记录,讲座,讲课等等来源的音视频,运用语音识别.视频内容提取等技术整理成word文档.项目中运用了以下技术: ...

  3. 用navicate 连接本地数据库提示用户名/口令无效

    1.在用navicate连接本地的oracle数据库时,试了oracle几个默认的用户名和密码,但是当我输入时,却提示用户名/口令无效.所以按照网上的办法,cmd,输入了以下命令,修改了几个用户的用户 ...

  4. freopen函数的使用以及freopen与fopen的区别

    freopen函数的使用:参见这篇博客https://www.cnblogs.com/moonlit/archive/2011/06/12/2078712.html 当我们求解acm题目时,通常在设计 ...

  5. C语言 puts

    C语言 puts #include <stdio.h> int puts(const char *s); 功能:标准设备输出s字符串,在输出完成后自动输出一个'\n'. 参数: s:字符串 ...

  6. 刷题72. Edit Distance

    一.题目说明 题目72. Edit Distance,计算将word1转换为word2最少需要的操作.操作包含:插入一个字符,删除一个字符,替换一个字符.本题难度为Hard! 二.我的解答 这个题目一 ...

  7. [Java] 多线程基础详细总结,附加详细实例

    详细代码在文章底部 目录 基础概念 进程与线程 单线程与多线程 实现线程的4中方式 thread.start()和runnable.run()的区别 Thread和Runnable的异同 线程的基本操 ...

  8. Flask 教程 第二十一章:用户通知

    本文翻译自The Flask Mega-Tutorial Part XXI: User Notifications 这是Flask Mega-Tutorial系列的第二十一章,我将添加一个私有消息功能 ...

  9. google插件跨域含用户请求WebApi解决的方案

    问题描述: google插件跨域请求WebApi相关解决方案 1.ajax解决含登录用户信息 $.ajax({ url: url, type: "POST", timeout: 6 ...

  10. js中map和filter方法,以及search方法

    链接:https://blog.51cto.com/11871779/2126561 search方法: 介绍: search() 方法用于检索字符串中指定的子字符串,或检索与正则表达式相匹配的子字符 ...