题意:给一个数组,求其中任取2个元素,大的模小的结果最大值。

一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减。那么lower_bound(kx)的前一个就是最优的值,用它模x更新。一旦最优值是最后一个元素,那么更新完后break;对数组排序完后对每个元素进行如上操作。(跳过1),复杂度为n/2+n/3+......=n(1/2+1/3+......)=nlogn。不过超时了。因为如果数组中全是2,最后一个为99999,复杂度为n/2+n/2+......=n*n/2。因此数组要去重。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon n;
cin>>n;
vector<lon> vct(n);
for(int i=;i<n;++i)
{
cin>>vct[i];
}
sort(vct.begin(),vct.end());
vct.erase(unique(vct.begin(),vct.end()),vct.end());
lon res=,last=;
for(int i=;i<vct.size();++i)
{
if(vct[i]!=)
for(lon j=;;++j)
{//j<(n/(i+2))+100
lon cur=vct[i]*j;
lon pos=lower_bound(vct.begin(),vct.end(),cur)-vct.begin();
--pos;
//if(i==199999)cout<<n<<" "<<pos<<" "<<vct[pos]<<endl;
res=max(res,vct[pos]%vct[i]);
//cout<<i<<" "<<cur<<endl;
if(pos==n-)break;
if(cur>1e6+)break;
}
}
cout<<res<<endl;
return ;
}

codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)的更多相关文章

  1. Codeforces 484B Maximum Value(高效+二分)

    题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...

  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 Round #276 (Div. 1)B. Maximum Value 筛法

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

  4. Codeforces Round #276 (Div. 2)D - Maximum Value(筛法)

    就是一种筛法思想的应用. #include<iostream> #include<cstdio> #include<cstdlib> #include<cst ...

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

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

  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. jquery日期时间控件

    代码下载地址:  jquery日期时间控件下载地址 .  工作中用到, 这里分享一下, 避免重复摸索劳动. 一. HTML 文件    <!DOCTYPE HTML PUBLIC "- ...

  2. 能让程序做的事情坚决不用人来做——批量修复markdownlint MD034警告

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  3. Linux用root强制踢掉已登录用户

    首先使用w命令查看所有在线用户: [root@VM_152_184_centos /]# w 20:50:14 up 9 days, 5:58, 3 users, load average: 0.21 ...

  4. 记一次ping: unknown host错误

    虚拟机上一台主机,之前一直在用,可以通过xshell连接,但是忽然发现ping百度失败了! [root@mgt02 ~]# ping www.baidu.com ping: unknown host ...

  5. gcc与glibc关系

    glibc是什么,以及与gcc的关系? glibc是gnu发布的libc库,也即c运行库.glibc是linux 系统中最底层的api(应用程序开发接口),几乎其它任何的运行库都会倚赖于glibc.g ...

  6. keepalived+nginx实现HA高可用的web负载均衡

    Keepalived 是一种高性能的服务器高可用或热备解决方案, Keepalived 可以用来防止服务器单点故障的发生,通过配合 Nginx 可以实现 web 前端服务的高可用.Keepalived ...

  7. VC 线程池

    参照:http://www.cnblogs.com/kzloser/archive/2013/03/11/2909221.html 参照:http://blog.csdn.net/pjchen/art ...

  8. 启动jenkins服务错误

    背景 重新安装了jenkins,需要启动,使用的yum install安装的,启动jenkins的话只需要执行service jenkins start,但出了两个问题 1. 是提示找不到java 2 ...

  9. HDU 2157(矩阵快速幂)题解

    How many ways?? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  10. SPOJ LAS(BFS)题解

    题目:VJ 思路: BFS+回溯,但是要剪枝,看了dalao的题解,超时+WA无数发,终于过了 #include<cstdio> #include<cstring> #incl ...