Maximum Value(CodeForces - 484B)
Maximum Value
Time limit 1000 ms
Memory limit 262144 kB
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.
Example
3
3 4 5
2 题意:求aj%ai的最大值,其中j>i;
分析:每次寻找小于k*aj的最大值,类似于素数筛,例如n=5时,3 4 5 6 7 ,我们如果查找对3取模的最大值,毫无疑问就是找到3到2*3中间的最大值; AC代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 2*100000+10
const int maxn=+;
typedef long long ll;
using namespace std;
int a[N];
int n;
int C(int x){
int w=x,ans=;
while (w<a[n-]){
w+=x;
int k=lower_bound(a,a+n,w)-a;
if (k==) continue;
else k--;
if (a[k]<=x) continue;
ans=max(ans,a[k]%x);
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
int ans=;
scanf("%d",&n);
for (int i=;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);
for (int i=n-;i>=;i--){
if (i<n-&&a[i]==a[i+])
continue;
if (ans>=a[i]-)
break;
ans=max(ans,C(a[i]));
}
printf("%d\n",ans);
return ;
}
Maximum Value(CodeForces - 484B)的更多相关文章
- Codeforces 484B Maximum Value(高效+二分)
题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...
- codeforces 484B B. Maximum Value(二分)
题目链接: B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces 484B Maximum Value(排序+二分)
题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最 ...
- CodeForces 484B Maximum Value (数学,其实我也不知道咋分类)
B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CodeForces 484B Maximum Value
意甲冠军: a序列n(2*10^5)数字 问道a[i]>=a[j]如果是 a[i]%a[j]最大值是多少 思路: 感觉是一道挺乱来的题-- 我们能够将ans表示为a[i]-k*a[j] 这 ...
- codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)
题意:给一个数组,求其中任取2个元素,大的模小的结果最大值. 一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减.那么lower_bound(kx)的前一个就是最优 ...
- CodeForces 484B 数学 Maximum Value
很有趣的一道题,题解戳这. #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- Educational Codeforces Round 32 Maximum Subsequence CodeForces - 888E (meet-in-the-middle,二分,枚举)
You are given an array a consisting of n integers, and additionally an integer m. You have to choose ...
- Maximum Questions CodeForces - 900E (字符串,dp)
大意:给定长$n$的字符串$s$, 只含'a','b','?', '?'可以替换为任意字符, 在给定长$t$的字符串, "ababab...", 求替换尽量少的'?', 使得$s$ ...
随机推荐
- [原]调试实战——使用windbg调试TerminateThread导致的死锁
原调试debugwindbg死锁deadlock 前言 项目里的一个升级程序偶尔会死锁,查看dump后发现是死在了ShellExecuteExW里.经验少,不知道为什么,于是在高端调试论坛里发帖求助, ...
- Python语言学习:homework2
三级菜单 # Author:Crystal data = { '北京':{ "昌平":{ "沙河":["oldbay","test ...
- TechEmpower 框架性能测试数据 - 新解读
1. TechEmpower Framework Benchmark 介绍 TechEmpower 框架性能大比拼平台从 2013 年 3 月开始以来已经历经了 18 轮测试,参与这个平台的框架平台产 ...
- 完成在本机远程连接HBase进行数据增删改查
1.进行hbase与本机远程连接测试连接 1.1 修改虚拟机文件hbase-site.xml(cd/usr/local/hbase/conf)文件,把localhost换成你的虚拟机主机名字 1.2修 ...
- DRF一对多序列化和反序列化
models.py # 商品分类 class Category(models.Model): name = models.CharField(max_length=32) # 商品 class Goo ...
- Oscar的拓扑笔记本
目录 Euler characteristic Euler定理 引入:绝对值 度量空间 Example: 开集,闭集 Topological space 什么是拓扑 拓扑空间 例子: Exercise ...
- [原]调试实战——使用windbg调试崩溃在ole32!CStdMarshal::DisconnectSrvIPIDs
原调试debugwindbg崩溃crash 前言 最近程序会不定期崩溃,很是头疼!今晚终于忍无可忍,下决心要干掉它!从之前的几个相关的dump可以猜到是有接口未释放导致的问题,但没有确认到底是哪个接口 ...
- chromosome interaction mapping|cis- and trans-regulation|de novo|SRS|LRS|Haplotype blocks|linkage disequilibrium
Dissecting evolution and disease using comparative vertebrate genomics-The sequencing revolution s ...
- Uber坚持不盈利,葫芦里到底卖的是什么药?
近日,据媒体报道在美国科罗拉多州阿斯彭举办的<财富>科技头脑风暴大会上,Uber CEO达拉·科斯罗萨西表示,Uber无需在2019年下半年上市计划实施前保持盈利状态. 首先要明确一点的是 ...
- Office.MsoLanguageID枚举常量(采用API函数取出)
msoLanguageIDAfrikaans (&H436) msoLanguageIDAlbanian (&H41C) msoLanguageIDAmharic (&H45E ...