就是一种筛法思想的应用。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=;
int n,a[maxn],ans=-;
int main()
{
//freopen("in9.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
if(n==){printf("0\n");return ;}
sort(a,a+n);
for(int i=;i<n-;i++)
{
if(i&&a[i]==a[i-]) continue;
for(int t=a[i]*;t<=a[n-];t+=a[i])
{
int p=lower_bound(a,a+n,t)-a;
ans=max(ans,a[p-]%a[i]);
}
ans=max(ans,a[n-]%a[i]);
}
printf("%d\n",ans);
//fclose(stdin);
//fclose(stdout);
return ;
}

Codeforces Round #276 (Div. 2)D - Maximum Value(筛法)的更多相关文章

  1. Codeforces Round #276 (Div. 1)B. Maximum Value 筛法

    D. Maximum Value     You are given a sequence a consisting of n integers. Find the maximum possible ...

  2. 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 ...

  3. codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)

    题意:给一个数组,求其中任取2个元素,大的模小的结果最大值. 一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减.那么lower_bound(kx)的前一个就是最优 ...

  4. Codeforces Round #276 (Div. 1) D. Kindergarten dp

    D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

  8. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  9. 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的数 维护 ...

随机推荐

  1. Python基础(11)_python模块之time模块、rando模块、hashlib、os模块

    一.模块 1.什么是模块:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀 模块的本质:模块的本质是一个py文件 2.模块分为三类:1)内置模块:2)第三方模块: ...

  2. pyhton3 sys模块

    Python常用模块之sys sys模块提供了一系列有关Python运行环境的变量和函数. 1 ). sys.stdin 标准输入流.2 ).sys.stdout 标准输出流.3 ). sys.std ...

  3. bfc (收集的)

    一些基本概念 viewport: 展现网页的媒体,比如窗口或者某个区域,它的大小是有限制的,为了不被平台术语所束缚,我们给他起名viewport,中文意思就是视口. canvas: 而我们在渲染网页的 ...

  4. 树莓派使用DHT11温湿度传感器(C语言程序)

    pi4j是基于wiringpi开发的通过java来控制树莓派GPIO口的库文件.在java程序中引入相关类就可以使用已经封装好的方法控制树莓派GPIO口. pi4j官网:http://pi4j.com ...

  5. JS以指定格式获取当前日期

    //获取当前时间,格式YYYY-MM-DD function getNowFormatDate() { var date = new Date(); var seperator1 = "-& ...

  6. 跨平台移动开发 Xuijs超轻量级的框架Style CSS属性用法

    PhoneGap里面推荐使用的超轻量级的框架 Style CSS属性用法 设置css属性:setstyle 通过ID设置css属性 x$('#top1').setStyle('color', '#DB ...

  7. systemverilog新增的always_comb,always_ff,和always_latch语句

    在Verilog中,设计组合逻辑和时序逻辑时,都要用到always: always @(*) //组合逻辑 if(a > b) out = 1; else out = 0; always @(p ...

  8. transition失效问题

    关于transition,css教程中有一个很简单的例子: <!DOCTYPE html> <html> <head> <meta charset=" ...

  9. MIPI DSI协议学习【转】

    本文转载自:http://www.voidcn.com/blog/LoongEmbedded/article/p-6109759.html 1.     MIPI DSI DSI:displayser ...

  10. VMware Big Data Extensions 安装步骤

    文档地址:https://pubs.vmware.com/bde-2/index.jsp 第一步,部署BigDataExtensions OVF模板,并登陆Console修改默认密码 第二步,在 Se ...