Codesforces 485D Maximum Value
You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of ai divided byaj), where 1 ≤ i, j ≤ n and ai ≥ aj.
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).
Print the answer to the problem.
3
3 4 5
2
给出 n 个数 a[0] ~ a[n-1] ,要你找出 a[i] % a[j] 最大.
处理一个数组x[i]表示 1~i 离i最近的数是什么。就可以过了。
#include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int mod = (1e9+);
const int N = ;
bool num[N];
int x[N] , a;
int main()
{
int n ;
cin >> n ;
for( int i = ; i < n ; ++i ) {
cin >> a;
num[a] = ;
}
for( int i = ; i <= 2e6 ; ++i ){
if( num[i] )x[i] = i ;
else x[i] = x[i-] ;
}
int res = ;
for( int i = ; i <= 1e6 ; ++i ) if( num[i] ){
for( int j = * i ; j <= 2e6 ; j += i ) {
res = max( res , ( x[j-] ) % i );
}
}
cout << res << endl;
}
Codesforces 485D Maximum Value的更多相关文章
- CodeForces - 485D Maximum Value (数学)
题意: n个数,求出这些数中满足 ai >= aj 的 ai % aj 的最大值. 排序去重,然后对于每一个a[i], 如果找到a[i] 的一个倍数 k*a[i] (k > 1)的位置,那 ...
- Codeforces C. Maximum Value(枚举二分)
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...
- POJ3693 Maximum repetition substring [后缀数组 ST表]
Maximum repetition substring Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9458 Acc ...
- Uncaught RangeError: Maximum call stack size exceeded 调试日记
异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html 开发道路上不是解决问题最重要,而是解决问题的过程,这个过程我们称之为~~~调试 记 ...
- iOS---The maximum number of apps for free development profiles has been reached.
真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...
- MTU(Maximum transmission unit) 最大传输单元
最大传输单元(Maximum transmission unit),以太网MTU为1500. 不同网络MTU如下: 如果最大报文数据大小(MSS)超过MTU,则会引起分片操作. 路径MTU: 网路 ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Third Maximum Number 第三大的数
Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...
随机推荐
- HTTP面试题目
转自:http://m.blog.csdn.net/zhangliangzi/article/details/51336564 1.说一下什么是Http协议? 对器客户端和 服务器端之间数据传输的格式 ...
- canvas时间粒子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python内存管理及垃圾回收
一.python的内存管理 python内部将所有类型分成两种,一种由单个元素组成,一种由多个元素组成.利用不同结构体进行区分 /* Nothing is actually declared to b ...
- Ptyhon 合并列表
2019-08-25 list1 = [91, 95, 97, 99] list2 = [92, 93, 96, 98] 合并后得到:[91, 95, 97, 99 , 92, 93, 96, 9 ...
- columns样式属性使用
columns样式属性使用 columns:用于设置元素的列宽和列数.它是column-width和column-count的简写属性. 语法: columns: <'column-width' ...
- Nginx的应用之虚拟主机
开始前请确保selinux关闭,否则当配置完虚拟主机后,尽管权限或者网站目录都正确,访问的结果也是403 nginx的虚拟主机有三种方式: 一.基于域名的虚拟主机 (1)创建对应的web站点目录以及程 ...
- Codeforces 1188C DP 鸽巢原理
题意:定义一个序列的beauty值为序列中元素之差绝对值的最小值,现在给你一个数组,问所有长度为k的子序列的beauty值的和是多少? 思路:(官方题解)我们先解决这个问题的子问题:我们可以求出bea ...
- OpenLayers API整理
整理的Openlayers 的知识笔记,随着运用不断加深理解,也会不断更新. 本文链接:Openlayers API整理 作者:狐狸家的鱼 GitHub:八至 一.创建地图 1.地图Map 创建地图底 ...
- python利用ConfigParser读写配置文件
ConfigParser 是Python自带的模块, 用来读写配置文件, 用法非常简单. 配置文件的格式是: []包含的叫section, section 下有option=value这样的键值 ...
- python 环境准备-centos7
python3环境搭建[本身centosyum底层也是py2.x实现的,装3.x的时候要实现多版本共存这里解决了这些问题] 安装编译环境# yum -y groupinstall 'Developme ...