Codeforces Round #276 (Div. 1)B. 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 题意:给你一个a数组,问你最大的ai%aj是多少(ai>aj);
题解:我们要求ai%aj最大,ai%(aj*k)最大,类似筛法去最大就是了
/// #include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
const int N=+;
#define mod 10000007
#define inf 1000000001
#define maxn 10000 int a[N];
int main() {
int n=read();
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
// H[a[i]]=1;
}
sort(a+,a+n+);
a[]=-;int ans=-;
for(int i=;i<=n;i++) {
if(a[i]==a[i-])continue;
for(int j=a[i]+a[i];j<=a[n];j+=a[i])
{
int tmp=lower_bound(a+,a+n+,j)-a;
ans=max(ans,a[tmp-]%a[i]);
}
ans=max(ans,a[n]%a[i]);
}
cout<<ans<<endl;
return ;
}
代码
Codeforces Round #276 (Div. 1)B. Maximum Value 筛法的更多相关文章
- Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数
B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/prob ...
- Codeforces Round #276 (Div. 2)D - Maximum Value(筛法)
就是一种筛法思想的应用. #include<iostream> #include<cstdio> #include<cstdlib> #include<cst ...
- codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)
题意:给一个数组,求其中任取2个元素,大的模小的结果最大值. 一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减.那么lower_bound(kx)的前一个就是最优 ...
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp排序
B. Maximum Submatrix 2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- Codeforces Round #276 (Div. 1) A. Bits 二进制 贪心
A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Des ...
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
随机推荐
- SQL之T-sql 语句操作数据库
用SQL语句操作数据库 在上一次的话题中我们谈到了怎么使用数据库,说到了数据库的基本用法. 不过只是仅限于一些简单的操作,so 如果你不想被人说--"你们只是动动鼠标操作就可以了! 没什么技 ...
- jQuery——this
js注册事件this代表的dom对象 jQuery注册事件this代表的也是dom对象,所以需要$(this)转成jQuery对象
- 【译】x86程序员手册04 - 2.2数据类型
2.2 Data Types 数据类型 Bytes, words, and doublewords are the fundamental data types (refer to Figure 2- ...
- 用sed替换含反斜(\)的字符串
今天在linux替换配置文件时,test文件里有一个字符串 e:\ 需要换成/usr/home/ 用了sed命令:sed -i "s?e:\\?/usr/home/?g" test ...
- lamlmzhang的新博客开通了,欢迎大家的关注
从这里开始lamlmzhang的java开发之路~!
- windons共享的一些问题
有时候访问共享一直说无法打开共享,但是别人确实是开了共享. 其中可能如下: 1.首先确定网络没有问题,win+R输入cmd,ping对方IP地址,保证是网络是通的,如果不通,关闭共享电脑的防火墙. 2 ...
- 基于fpga uart学习笔记
2018年7月24日 uart 接收 部分测试成功,多谢开源骚客 邓堪文老师 ,想学的同学可以微信公众号搜索开源骚客 好啦!言归正传. 1.先附上老师的时序图,自己有点懒不想画,rx_t.rx_tt. ...
- 11.11如何卖到一个亿:从0到1的电商爆品打造术 电子书 PDF
内容转自:https://download.csdn.net/download/chenyao1994/11191034 下载地址:https://pan.baidu.com/s/1uQ1cjm9QH ...
- 多目标跟踪笔记一:Finding the Best Set of K Paths Through a Trellis With Application to Multitarget Tracking
Abstract 本文提出一种寻找K最优路径的方法. k最优路径的定义:1.the sum of the metrics of all k paths in the set is minimized. ...
- 1.git上手篇总结
阅读 Git 原理详解及实用指南 记录 上手 1: Git 的最基本的工作模型 从 GitHub 把中央仓库 clone 到本地(使用命令: git clone) 把写完的代码提交(先用 git ad ...