Codeforces485D(SummerTrainingDay01-K)
D. Maximum Value
You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.
Input
The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).
The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).
Output
Print the answer to the problem.
Examples
input
3
3 4 5
output
2
//2017-08-17
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; const int N = ;
const int M = ;
//book[i]记录i是否出现过,pre[i]表示比i小的出现过的最大的数
int a[N], n, book[M], pre[M]; int main()
{
while (scanf("%d", &n) != EOF)
{
memset(book, , sizeof(book));
for (int i = ; i < n; i++){
scanf("%d", &a[i]);
book[a[i]] = ;
}
sort(a, a + n);
n = unique(a, a+n)-a;
int ans = , maxinum = (a[n-]<<), ptr = ;
for(int i = ; i <= maxinum; i++){
pre[i] = ptr;
if(book[i])ptr = i;
}
for (int i = ; i < n; i++){
for (int j = a[i]<<; j <= maxinum; j+=a[i]){
ans = max(ans, a[i]-j+pre[j]);
}
}
printf("%d\n", ans);
}
return ;
}
Codeforces485D(SummerTrainingDay01-K)的更多相关文章
- django模型操作
Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表
- 基于改进人工蜂群算法的K均值聚类算法(附MATLAB版源代码)
其实一直以来也没有准备在园子里发这样的文章,相对来说,算法改进放在园子里还是会稍稍显得格格不入.但是最近邮箱收到的几封邮件让我觉得有必要通过我的博客把过去做过的东西分享出去更给更多需要的人.从论文刊登 ...
- 【开源】专业K线绘制[K线主副图、趋势图、成交量、滚动、放大缩小、MACD、KDJ等)
这是一个iOS项目雅黑深邃的K线的绘制. 实现功能包括K线主副图.趋势图.成交量.滚动.放大缩小.MACD.KDJ,长按显示辅助线等功能 预览图 最后的最后,这是项目的开源地址:https://git ...
- 找到第k个最小元----快速选择
此算法借用快速排序算法. 这个快速选择算法主要利用递归调用,数组存储方式.包含3个文件,头文件QuickSelect.h,库函数QuickSelect.c,测试文件TestQuickSelect. 其 ...
- BZOJ 3110: [Zjoi2013]K大数查询 [树套树]
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6050 Solved: 2007[Submit][Sta ...
- 二次剩余、三次剩余、k次剩余
今天研究了一下这块内容...首先是板子 #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...
- K近邻法(KNN)原理小结
K近邻法(k-nearst neighbors,KNN)是一种很基本的机器学习方法了,在我们平常的生活中也会不自主的应用.比如,我们判断一个人的人品,只需要观察他来往最密切的几个人的人品好坏就可以得出 ...
- YYStock开源----iOS股票K线绘制第二版
新的股票绘制粗来啦,欢迎围观star的说(*^__^*) 嘻嘻-- 捏合功能也准备完善了 Github:https://github.com/yate1996/YYStock 长按分时图+五档图 分时 ...
- k近邻算法(knn)的c语言实现
最近在看knn算法,顺便敲敲代码. knn属于数据挖掘的分类算法.基本思想是在距离空间里,如果一个样本的最接近的k个邻居里,绝大多数属于某个类别,则该样本也属于这个类别.俗话叫,"随大流&q ...
随机推荐
- C#6.0语言规范(十八) 不安全代码
前面章节中定义的核心C#语言与C和C ++的区别在于它省略了作为数据类型的指针.相反,C#提供了引用和创建由垃圾收集器管理的对象的能力.这种设计与其他功能相结合,使C#成为比C或C ++更安全的语言. ...
- D3.js (v3)+react框架 基础部分之认识选择集和如何绘制一个矢量图
首先需要下载安装d3.js : yarn add d3 然后在组建中引入 : import * as d3 from 'd3' 然后定义一个方法,在componentDidMount()这个钩子 ...
- 使用IEDA远程调试
下面演示在docker中调试代码. 使用vulhub作为演示. 下载vulhub,进入vulhub/fastjson/vuln/ 编辑docker-compose.yml ,在最后新建一行加入 - ...
- cookie、session的区别
相信你肯定经常听说cookie和Session,那你有没有好好了解这两个的区别呢?其实,不整理之前,我也是一脸懵. 为什么需要cookie和session呢?---因为Http是无状态的,web开发中 ...
- 【sping揭秘】10、SpringIOC容器扩展
关于component-scan操作(去除,失效) 这个spring中的配置项,可以扫描我们对应的包下面的类,自动把带上@component,@service,@controller, @reposi ...
- Java时间类(转)
package com.chinagas.common.utils; import java.text.ParseException; import java.text.SimpleDateForma ...
- android的电话监听
android的电话监听 新建一个项目,结构图如下: PhoneService: package com.demo.tingdianhua; import android.app.Service; i ...
- ERROR tool.ImportTool: Encountered IOException running import job: java.io.IOException: Cannot run program "hive": error=2, No such file or directory
原因是hive没有设置环境变量 1,vim /etc/profile (切换root用户) 2.source /etc/profile
- 微信小程序(wx:for)遍历对象
最近在折腾微信小程序,遇到这么一个情况:后端返回一个key-value的对象数据,需要遍历对象的key-value,然后渲染到视图中.就像下面这样: { '2018-1-9':{ address: ' ...
- 分析Item
分析Item例子1: class Parent { /* <init>() { super(); // JCES树节点,Item(void) px = 0; // JCES树节点,Assi ...