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 ...
随机推荐
- java.lang.System.setProperty()方法实例
java.lang.System.setProperty() 方法设置指定键指定的系统属性. 声明 以下是java.lang.System.setProperty()方法的声明 public stat ...
- Swift5 语言参考(二) 词法结构
词汇结构 Swift 的词法结构描述了什么样的字符序列形成了语言的有效标记.这些有效令牌构成语言的最低级构建块,用于描述后续章节中的其余语言.令牌由标识符,关键字,标点符号,文字或运算符组成. 在大多 ...
- Liferay开发实战(1):入门
网址: https://www.liferay.com/zh/ 文档: https://dev.liferay.com/develop 入门文章网上很多,中文的较少,存在版本太旧的问题,也缺少一步一步 ...
- 08-03 java 继承
继承格式,优缺点,概述: /* 继承概述: 把多个类中相同的内容给提取出来定义到一个类中. 如何实现继承呢? Java提供了关键字:extends 格式: class 子类名 extends 父类名 ...
- Nutch抓取流程
nutch抓取流程注入起始url(inject).生成爬取列表(generate).爬取(fetch).解析网页内容(parse).更新url数据库(updatedb)1:注入起始url(inject ...
- Ruby:Nokogiri
阅读推荐: Nokogiri的用法我推荐三篇非常给力的文章: http://ruby.bastardsbook.com/chapters/html-parsing/ http://ruby.basta ...
- Your Mac is infected with (3) Viruses!
记一次流氓程序的清理 某天我的电脑不幸感染了这么一个病毒
- iOS 8.0 bluetooth peripheral manager giving no callback for addService
I am adding the service using: [self.peripheralManager addService:myService]; Is this method depreca ...
- Android_对android虚拟机的理解,包括内存管理机制垃圾回收机制。dalvik和art区别
虚拟机很小,空间很小,谈谈移动设备的虚拟机的大小限制 16M ,谈谈加载图片的时候怎么处理大图片的,outmemoryExceptionBitmapFactory.option 垃圾回收,没有引用的对 ...
- 全网最详细的hive-site.xml配置文件里添加<name>hive.cli.print.header</name>和<name>hive.cli.print.current.db</name>前后的变化(图文详解)
不多说,直接上干货! 比如,你是从hive-default.xml.template,复制一份,改名为hive-site.xml 一般是 <configuration> <prope ...