【PAT甲级】1085 Perfect Sequence (25 分)
题意:
输入两个正整数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 分)的更多相关文章
- 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 ...
- 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 ...
- PAT 甲级 1085 Perfect Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...
- 1085 Perfect Sequence (25 分)
Given a sequence of positive integers and another positive integer p. The sequence is said to be a p ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- PAT 甲级 1020 Tree Traversals (25 分)(二叉树已知后序和中序建树求层序)
1020 Tree Traversals (25 分) Suppose that all the keys in a binary tree are distinct positive integ ...
- 1085. Perfect Sequence (25) -二分查找
题目如下: Given a sequence of positive integers and another positive integer p. The sequence is said to ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
随机推荐
- Whctf 2017 -UNTITLED- Writeup
Whctf 2017 -UNTITLED- Writeup 转载请表明出处http://www.cnblogs.com/WangAoBo/p/7541481.html 分析: 下载下来的附件是一个py ...
- asp.net使用wsdl文件调用接口,以及调用SSL接口报错“根据验证过程 远程证书无效”的处理
1.调用wsdl接口,首先需要将wsdl文件转换为cs文件: 进入VS 开发人员命令提示行,输入如下命令: c:/Program Files/Microsoft Visual Studio 8/VC& ...
- Ninject 2.x细说---2.绑定和作用域
Ninject 2.x细说---2.绑定和作用域 转载weixin_33725272 最后发布于2011-11-06 00:03:00 阅读数 9 收藏 Ninject中提供多种接口和实现类的绑 ...
- SpringBean的生命周期以及循环依赖过程
上面就是springBean的大致生命周期. Bean的创建过程 创建Bean之前会调用Bean工厂的后置处理器,可以获取到BeanDefinition Bean的初始化过程 初始化之前会调用前置处理 ...
- 并发之atomic原子操作
Atomic类 Atomic类是一个简单的高效的.线程安全的递增递减方案,在多线程或者并发环境中,我们常常会遇到这种情况 int i=0; i++ 稍有经验的同学都知道这种写法是线程不安全的.为了达到 ...
- 【网页浏览】怀旧xp画图网页版
非常古老的WindowsXP画图工具 传送链接
- spring cloud config 连接GitHub访问 报错 Cannot clone or checkout repository
原因是建立仓库的时候将仓库私有化了,将仓库公有 或者 设置账号密码即可!
- 题解 P5594 【【XR-4】模拟赛】
P5594 [[XR-4]模拟赛] 洛谷10月月赛 II & X Round 4 Div.2前两道签到题还是很简单的,基本上是半小时内一遍过两题 看看题解,这题STL做法有用set输出size ...
- Redis读写分离的简单配置
Master进行写操作,可能只需要一台Master.进行写操作,关闭数据持久化. Slave进行读操作,可能需要多台Slave.进行读操作,打开数据持久化. 假设初始配置有Master服务器为A,sl ...
- 计算几何-LA2218-HPI-第一次卡精度-vijos1087-铁人三项
This article is made by Jason-Cow.Welcome to reprint.But please post the writer's address. http://ww ...