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

#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. redis设置密码后的重启问题

    Redis 设置密码登陆后使用 /etc/init.d/redis_6379 restart会出现:[root@8183539155d2 /]# /etc/init.d/redis_6379 rest ...

  2. ajax发送js类型的数据

    一.如图所示 var ids = [1,2,3,4,5,6,7] $.ajax({ url: requestUrl, type: 'delete', data: JSON.stringify(ids) ...

  3. 剑指offer 面试8题

    面试8题: 题目:二叉树的下一个节点 题目描述:给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. 解题思路:详见剑 ...

  4. War-ftpd USER longString漏洞攻击之Java实现常见问题

    发表这篇文章的最重要原因是,在用Java实现War-ftpd缓冲区溢出实验时,我遇到了很多问题,而且我认为这些问题 都是非常不容易发现和解决的,为了以后学习的同学的便利,此处写下自己遇到的问题作为分享 ...

  5. C#对Excel中指定一列或一行实现隐藏或显示!

    C#对Excel中指定一列或一行实现隐藏或显示!不会,求指导!

  6. ubuntu搭建mib2c环境

    1.下载net-snmphttp://net-snmp.sourceforge.net/download.html例如,下载5.5版本2.进入下载目录,解压net-snmp压缩包#tar zxf ne ...

  7. android 对话框中的进度条 (ProgressDialog)

    from:http://byandby.iteye.com/blog/817214 显然要定义对话框进度条就要用ProgressDialog,首先我们需要创建ProgressDialog对象,当然这里 ...

  8. 流量分析系统----讲解-echarts模拟迁移(结合china.js)

    百度 Echarts 地图->模拟迁徙,实现自动切换地图 小航哥注释: 1.本文主要是把模拟迁移的流程讲了一遍,讲的很好.具体实现参考航哥这篇随笔“流量分析系统----实现-echarts模拟迁 ...

  9. margin无法居中原因

    1.要给居中的元素一个宽度,否者无效. 2.该元素一定不能浮动,否者无效. 3 在HTML中使用标签,需考虑好整体构架,否者全部元素都会居中的.

  10. css小技巧1

    资料 1. 文本省略 单行省略: white-space:nowrap; overflow:hidden; text-overflow:ellipsis; 多行文本省略: 只兼容webkit内核,不属 ...