PAT (Advanced Level) 1085. Perfect Sequence (25)
可以用双指针(尺取法),也可以枚举起点,二分终点。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; int n;
long long k;
long long a[ + ]; int main()
{
scanf("%d%lld", &n, &k);
for (int i = ; i <= n; i++) scanf("%lld", &a[i]);
sort(a + , a + + n);
int ans = ;
for (int i = ; i <= n; i++)
{
int p;
int L = i, R = n;
while (L <= R)
{
int mid = (L + R) / ;
if (a[mid] <= a[i] * k)
{
p = mid;
L = mid + ;
}
else R = mid - ;
}
ans = max(ans, p - i + );
}
printf("%d\n", ans);
return ;
}
PAT (Advanced Level) 1085. Perfect Sequence (25)的更多相关文章
- PAT (Advanced Level) 1051. Pop Sequence (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 【PAT甲级】1085 Perfect Sequence (25 分)
题意: 输入两个正整数N和P(N<=1e5,P<=1e9),接着输入N个正整数.输出一组数的最大个数使得其中最大的数不超过最小的数P倍. trick: 测试点5会爆int,因为P太大了.. ...
- 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 ...
- 1085. Perfect Sequence (25) -二分查找
题目如下: Given a sequence of positive integers and another positive integer p. The sequence is said to ...
- 1085 Perfect Sequence (25 分)
Given a sequence of positive integers and another positive integer p. The sequence is said to be a p ...
- 1085. Perfect Sequence (25)
the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1085 At first ...
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT (Advanced Level) 1109. Group Photo (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1105. Spiral Matrix (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...
随机推荐
- shell之路【第三篇】流程控制
if语句 if ... fi 语句: if ... else ... fi 语句: if ... elif ... else ... fi 语句. 注意: expression 和方括号([ ])之间 ...
- Ubuntu DNS bind9 配置
下面的配置就是实现解析test.zp.com到不同的IP地址 安装dns server软件包$ apt-get install bind9 配置dns配置文件的路径在/etc/bind路径下面添加一个 ...
- centos7配置ip
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 ONBOOT=yes 重启ip服务 systemctl restart network.service 开 ...
- laravel路由使用【总结】
1.路由参数 必选参数 有时我们需要在路由中捕获 URI 片段.比如,要从 URL 中捕获用户 ID,需要通过如下方式定义路由参数: Route::get('/test_param/{id}', 'T ...
- cscope
http://sourceforge.net/p/cscope/bugs/247/ buffer read only? cx cq Here is a simple patch which re-en ...
- sql server 数据库导出表里所有数据成insert 语句
有时候,我们想把数据库的某张表里的所有数据导入到另外一个数据库或另外一台计算机上的数据库,对于sql server有这样的一种方法 下面我以sql server 2008 R2,数据库是Northwi ...
- oracle中触发器的讲解
触发器在数据库里以独立的对象存储,它与存储过程和函数不同的是,存储过程与函数需要用户显示调用才执行,而触发器是由一个事件来启动运行.即触发器是当某个事件发生时自动地隐式运行.并且,触发器不能接收参数. ...
- dedecms 标签的基本用法
1.关键描述调用标签: <meta name="keywords" content="{:fieldname='keywords'/}"> < ...
- sql快速参考
SQL 语句 语法 AND / OR SELECT column_name(s)FROM table_nameWHERE conditionAND|OR condition ALTER TABLE A ...
- 关于glibc中的res_init()函数
/* * Set up default settings. If the configuration file exist, the values * there will have precede ...