Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数
B. Maximum Value
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/484/problem/B
Description
Input
The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).
The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).
Output
Print the answer to the problem.
Sample Input
3
3 4 5
Sample Output
2
HINT
题意
给你n个数(n<=1e5),每个数(大小<=2*1e6),要求找到最大的ai%aj(ai>aj)
题解:
类似于筛法,对于每个数,我们都筛出他的倍数
ai%aj最大,可以转化为ai*k-aj最小,记录下每个数的倍数的前面的最大的数就好了
代码
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std; int pre[]; int main()
{
int n;scanf("%d",&n);
for(int i=;i<=n;i++)
{
int x;scanf("%d",&x);
pre[x]=x;
}
for(int i=;i<=;i++)
pre[i]=max(pre[i],pre[i-]);
int ans = ;
int flag = ;
for(int i=;i<=;i++)
{
if(pre[i]==i)
for(int j=i;j<=;j+=i)
ans = max(pre[i+j-]%i,ans);
}
printf("%d\n",ans);
}
Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数的更多相关文章
- 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 ...
- Codeforces Round #276 (Div. 2)D - Maximum Value(筛法)
就是一种筛法思想的应用. #include<iostream> #include<cstdio> #include<cstdlib> #include<cst ...
- codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)
题意:给一个数组,求其中任取2个元素,大的模小的结果最大值. 一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减.那么lower_bound(kx)的前一个就是最优 ...
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- 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 ...
- 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 ...
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- 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的数 维护 ...
随机推荐
- 【Unity3D】枪战游戏—弹孔设置
以子弹为原点,发射射线,如果射线检测到障碍物,则返回射线与障碍物的碰撞点 在该点处实例化出弹孔贴图 void Update () { transform.Translate (Vector3.forw ...
- 【DFS,双向】NYOJ-20-吝啬的国度
[题目链接:NYOJ-20] 很巧妙,要好好想想 #include <iostream> #include <stdio.h> #include <vector> ...
- Andorid-如何为你的Android应用缩放图片
很难为你的应用程序得到正确的图像缩放吗?是你的图片过大,造成内存问题?还是图片不正确缩放造成不良用户体验的结果?为了寻求一个好的解决方案,我们咨询了Andreas Agvard(索尼爱立信软件部门), ...
- 一个好用的hibernate泛型dao
以前从springside2.0上搞下来的很好用的,基本实现dao零编码只要配置xml文件就行了. 先看图: 一共4层,com.demonstration.hibernate.basedao是我加的用 ...
- 连接Excel文件时,未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序
问题与解决 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序 错误. string strCon = " Provider = Microsoft.Jet.OL ...
- C# 中LinkLabel的简单使用
界面中加入一个LinkLabel控件
- Android:实现一种浮动选择菜单的效果
总结如何实现Android浮动层,主要是dialog的使用. 自定义一个类继承自Dialog类,然后在构造方法中,定义这个dialog的布局和一些初始化信息. 案例1: public class Me ...
- Delphi RICHEDIT中插入图象
unit InsRich;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- duilib中的V和H布局中滚动条问题
转自博客:http://blog.csdn.net/damingg/article/details/41149037 首先看一段xml代码 [html] view plaincopy <?xml ...
- android sensor传感器系统架构初探
http://blog.csdn.net/qianjin0703/article/details/5942579 http://blog.chinaunix.net/uid-28621021-id-3 ...