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

#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. C#基础之匿名方法实例教程

    本文以实例形式讲解了C#的匿名方法的用法,分享给大家供大家参考之用.具体如下: 匿名方法是C# 2.0的语言新特性.首先看个最简单的例子: class Program { static void Ma ...

  2. vmware网络配置(NAt模式)

    学习参考: http://www.linuxidc.com/Linux/2017-03/141864.htm(讲解NAT模式) 配置: 1.在virtul Network Editor(虚拟网络编辑器 ...

  3. 【HackerRank】Pairs

    题目链接:Pairs 完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数.总结其实就是“骑驴找马”的问题:即当前遍历ar[ ...

  4. android 加固防止反编译-重新打包

    http://blog.csdn.net/u010921385/article/details/52505094 1.需要加密的Apk(源Apk) 2.壳程序Apk(负责解密Apk工作) 3.加密工具 ...

  5. Swing 添加超链接 打开页面

    http://lazycat774880994.iteye.com/blog/567412  Swing中打开一个连接或者web页面的一些记录,这几种方式是在项目中有这样子用到过,特来记录一下,以便下 ...

  6. 网络:W5500 UDP数据包格式注意事项

     1. 主题 使用W5500测试UDP功能,发现收到的数据包和wireshark抓包的数据不同. 原来W5500接收寄存器的数据包并不是网络上的数据流,而是经过内部处理后展现出来的. 对于这个问题目前 ...

  7. 关于在windows命令提示符cmd下运行Java程序的问题

    1. win+R出现cmd运行窗口,输入Java源码文件名运行时,错误: 找不到或无法加载主类... 问题背景:我已经配置好了Java环境(安装路径PATH,JAVA_HOME已装好,cmd运行jav ...

  8. Go bufio库

    bufio.Scanner bufio包使处理输入和输出方便又高效.Scanner类型是该包最有用的特性之一,它读取输入并将其拆成行或单词:通常是处理行形式的输入最简单的方法.该变量从程序的标准输入中 ...

  9. 树 List Leaves 【用数组模拟了树状结构建树+搜索叶子节点+按照特殊规律输出每个叶子节点】

    Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. I ...

  10. 8.14比赛j题 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87813#overview

    就我个人来说我觉得这道题其实不用写题解,只是因为做的时候错了一次,如果不是队友细心,我根本会错下去,所以我感觉自己必须强大#include<stdio.h> #include<str ...