意甲冠军:

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. C# 中 双问号??的用法

    int? x = null;int y = x ?? -1; 这里的y不能为null,但是等于x,x为null时赋值给y会报错.?? 可以在x==null时对y赋值-1 更多相关资料:https:// ...

  2. android绑定Service失败原因

    今天抄一个代码,学习Service,中间Service的绑定一直是失败的. bindService返回false 上网查询的话都是一些,比如说TabHost的问题 发现和自己的问题不一样. 最后想了想 ...

  3. Swift - 给图片添加文字水印(图片上写文字,并可设置位置和样式)

    想要给图片添加文字水印或者注释,我们需要实现在UIImage上写字的功能. 1,效果图如下: (在图片左上角和右下角都添加了文字.) 2,为方便使用,我们通过扩展UIImage类来实现添加水印功能 ( ...

  4. UVA 10574 - Counting Rectangles(枚举+计数)

    10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保 ...

  5. ASP.NET - 编写让别人能读懂的代码

    http://www.cnblogs.com/richieyang/p/4840614.html

  6. Maven 实现Struts2注解配置步骤详解

    1,pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...

  7. 关于WM_ERASEBKGND和WM_PAINT的深刻理解

    一直以来,对于WM_PAINT和WM_ERASEBKGND消息不是很清楚,从书上和网上找了很多资料,大体上有以下几点说法:1>WM_PAINT先产生,WM_ERASEBKGND后产生 2.WM_ ...

  8. Windows 8 动手实验系列教程 实验5:进程生命周期管理

    动手实验 实验5:进程生命周期管理 2012年9月 简介 进程生命周期管理对构建Windows应用商店应用的开发者来说是需要理解的最重要的概念之一.不同于传统的Windows应用(它们即使在后台仍然继 ...

  9. jstorm简介(转)

    Jstorm是参考storm的实时流式计算框架,在网络IO.线程模型.资源调度.可用性及稳定性上做了持续改进,已被越来越多企业使用 作为commiter和user,我还是非常看好它的应用前景,下面是在 ...

  10. Oracle实用-01:绑定变量

    数据库虽然在学校系统学习过,但是在工作中真正使用起来收获又是不一样的,今天起打算将项目中使用到的技术再分享出来,不以书本的顺序,只从碰到的问题为顺序. 虽然不是纯粹的数据库工程师,但是每个程序员总免不 ...