意甲冠军:

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. 基于visual Studio2013解决面试题之1201链表去重

     题目

  2. 执行shell脚本提示“syntax error near unexpected token for((i=0;i&lt;$length;i++))”

    sh脚本例如以下: #!/usr/bin/env bash county="3 4 5 6 7 8 9 10 11 12 16 29 39 44 53 62 72 84 97 115 128 ...

  3. java-创建线程的两种方式

    1. 继承Thread类 定义类继承Thread类. 覆盖run方法. 实例化子类对象,调用start()方法,从而调用run方法. 2.实现Runnable接口 定义类实现Runnable接口. 覆 ...

  4. ASP.NET - 对URL传递的值进行编码Server.UrlEncode()

    /// <summary> /// 搜索内容 /// </summary> /// <param name="sender"></para ...

  5. Eclipse用法和技巧十七:覆盖父类方法

    在学校里面学习java,遇到访问权限修饰符一直停留在public是公有的,外面可以访问:protected是对子类可见的,外部不可以访问:private仅在本类中可见.工作之后,接触到了java代码多 ...

  6. Oracle 创建索引的基本规则总结

    1.  选择索引字段的原则: 在WHERE子句中最频繁使用的字段 联接语句中的联接字段 选择高选择性的字段(如果很少的字段拥有相同值,即有很多独特值,则选择性很好) Oracle在UNIQUE和主键字 ...

  7. python发送各类邮件的主要方法

    更多详见: http://www.w3cschool.cc/python/python-email.html python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法 ...

  8. 如何在一个jpg图片上面叠加文字

    1.将jpg转为bmp格式 2.在bmp文件上写上所需文字 3.将写入文字的bmp文件重新转为jpg格式 http://dev.csdn.net/develop/article/22/22948.sh ...

  9. WordPress数据备份

    服务器钱用光了要关了或者是服务器想要搬家,需要备份各种数据. 今天简单的备份了一下在服务器上面wordpress各种文件和资源. wordpress的数据主要分两个部分,一个是文字部分的:一个是附件部 ...

  10. Solaris 11的自动化安装(AI server)的搭建

    solaris 11 总体比solaris 10很多变动的地方,可以去官方网站上面学习:http://www.oracle.com/technetwork/server-storage/solaris ...