意甲冠军:

a序列n(2*10^5)数字  问道a[i]>=a[j]如果是  a[i]%a[j]最大值是多少

思路:

感觉是一道挺乱来的题……

我们能够将ans表示为a[i]-k*a[j]  这样我们枚举k仅仅要知道比k*a[j]大可是不到(k+1)*a[j]的值就好了  考虑到a[i]仅仅要10^6大  因此能够用一个last数组记录小于等于i的数组中的数字  因此仅仅要拿出last[(k+1)*a[j]-1]就好

暴力可能会T有一些能够让程序加速的方法  输入开挂  a数字去重  从大到小枚举a[i]当ans>=a[i]时候能够break

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
using namespace std;
typedef long long LL;
#define N 200010
#define M 1000010 int a[N], last[M];
int n, ans; inline void scand(int &ret) {
char c;
ret = 0;
while ((c = getchar()) < '0' || c > '9')
;
while (c >= '0' && c <= '9')
ret = ret * 10 + (c - '0'), c = getchar();
} int main() {
scand(n);
for (int i = 1; i <= n; i++) {
scand(a[i]);
last[a[i]] = a[i];
}
for (int i = 1; i < M; i++) {
if (!last[i])
last[i] = last[i - 1];
}
sort(a + 1, a + n + 1);
n = unique(a + 1, a + n + 1) - a - 1;
for (int i = n - 1; i >= 1; i--) {
if (a[i] <= ans)
break;
for (int j = a[i] * 2; j < M && j - a[i] <= a[n]; j += a[i]) {
ans = max(ans, last[j - 1] % a[i]);
}
ans = max(ans, last[M - 1] % a[i]);
}
printf("%d\n", ans);
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

CodeForces 484B Maximum Value的更多相关文章

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

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

  2. Codeforces 484B Maximum Value(排序+二分)

    题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最 ...

  3. CodeForces 484B Maximum Value (数学,其实我也不知道咋分类)

    B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

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

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

  5. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. codeforces 484B B. Maximum Value(二分)

    题目链接: B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Maximum Value(CodeForces - 484B)

    Maximum Value Time limit 1000 ms Memory limit 262144 kB You are given a sequence a consisting of n i ...

  8. CodeForces 484B 数学 Maximum Value

    很有趣的一道题,题解戳这. #include <iostream> #include <cstdio> #include <cstring> #include &l ...

  9. [codeforces 508E]Maximum Matching

    题目:Maximum Matching 传送门:http://codeforces.com/contest/1038/problem/E 分析: 一个块拥有{color1,val,color2},两个 ...

随机推荐

  1. 仿Google首页搜索自动补全

    仿Google自动补全,实现细节: 后台是简单的servlet(其实就是负责后台处理数据交互的,没必要非跌用个struts...什么的) 传输介质:xml 使用jQuery js框架 功能实现: 如果 ...

  2. ajax动态加载的图标

    http://www.ajaxload.info/ 这个网站可以动态生成ajax加载样式的小图片,git格式,挺不错推荐给大家

  3. 基于visual Studio2013解决C语言竞赛题之1037数组求列和

          题目 解决代码及点评 /* 功能:已知有三个数组A,B,C,A为5行5列的二维数组,B.C为只有5个元素的一维数组,键盘输入数据的顺序如下: 23,45,6,1,- ...

  4. 基于visual Studio2013解决C语言竞赛题之1026判断排序

          题目 解决代码及点评 /********************************************************************** ...

  5. 教师简介 (Alma Del Tango的小站)

    教师简介 (Alma Del Tango的小站) Esteban Peng (TT) & Emilia Jia (Amy) TT和Amy是北京极具影响力的专业舞者,他们从07年开始推广阿根廷探 ...

  6. perl 匿名函数传参

    $subref=sub { my $a=shift; return $a; }; print $subref->("xxyyzz");

  7. 1.1.6-学习Opencv与MFC混合编程之---播放WAV音乐和 alpha融合功能

    源代码:http://download.csdn.net/detail/nuptboyzhb/3961698 Alpha融合菜单项 1.      增加alpha融合菜单项,修改相应的属性,建立类向导 ...

  8. javascript 回调函数应用

    回调函数是什么在学习之前还真不知道js回调函数怎么使用及作用了,下面本文章把我在学习回调函数例子给各位同学介绍一下吧,有需了解的同学不防进入参考. 回调函数原理: 我现在出发,到了通知你”这是一个异步 ...

  9. MTU & MSS 详解记录(转)

              先学习理解一下帧的封装格式:   需要注意的是,区别两种帧封装格式:802标准帧和以太网帧 1,在802标准定义的帧格式中,长度字段是指它后续数据的字节长度,但不包括C R C检验 ...

  10. 深入研究Clang(四) Clang编译器的简单分析

    作者:史宁宁(snsn1984) 首先我们确定下Clang编译器的详细内容和涵盖范围.之前在<LLVM每日谈之二十 Everything && Clang driver>中 ...