CodeForces 484B Maximum Value (数学,其实我也不知道咋分类)
1 second
256 megabytes
standard input
standard output
You are given a sequence a consisting of n integers. Find the maximum possible value of
(integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.
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).
Print the answer to the problem.
3
3 4 5
2 题意:给一堆数,然后要求找两个数,大的数除小的数求余,求最大的余值是多少 思路:类似筛表法的思想,对于每个aj找ai。对每个aj,就for(p=aj;p<mx;p+=aj) 然后二分一下找小于a[p]且最接近a[p]的数,然后用这个数维护答案。另外一点由于这里的数只有10^6,所以可以不用二分找最靠近的数,用一个数组直接维护就可以了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1e9;
const double eps = 1e-;
const int N = ;
const int M = ;
int cas = ; int a[N];
bool vis[M];
int num[M];
int n,mxnum,ans; void run()
{
int x;
mxnum=;
memset(vis,,sizeof(vis));
memset(num,,sizeof(num));
for(int i=;i<n;i++)
{
scanf("%d",&x);
if(mxnum<x) mxnum=x;
vis[x]=;
}
for(int i=;i<=mxnum;i++)
{
if(vis[i]) num[i]=i;
else num[i]=num[i-];
}
ans=;
for(int aj=;aj<=mxnum;aj++)
{
if(!vis[aj]) continue;
if(ans<mxnum%aj) ans=mxnum%aj;
for(int p=aj*;p<=mxnum;p+=aj)
{
if(ans < num[p-]%aj)
ans = num[p-]%aj;
}
}
printf("%d\n",ans);
} int main()
{
#ifdef LOCAL
// freopen("case.txt","r",stdin);
#endif
while(scanf("%d",&n)!=EOF)
run();
return ;
}
CodeForces 484B Maximum Value (数学,其实我也不知道咋分类)的更多相关文章
- Codeforces 484B Maximum Value(高效+二分)
题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...
- Codeforces 484B Maximum Value(排序+二分)
题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最 ...
- CodeForces 484B Maximum Value
意甲冠军: a序列n(2*10^5)数字 问道a[i]>=a[j]如果是 a[i]%a[j]最大值是多少 思路: 感觉是一道挺乱来的题-- 我们能够将ans表示为a[i]-k*a[j] 这 ...
- codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)
题意:给一个数组,求其中任取2个元素,大的模小的结果最大值. 一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减.那么lower_bound(kx)的前一个就是最优 ...
- Codeforces C. Maximum Value(枚举二分)
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...
- BITED数学建模七日谈之四:数学模型分类浅谈
本文进入到数学建模七日谈第四天:数学模型分类浅谈 大家常常问道,数学模型到底有哪些,分别该怎么学习,这样能让我们的学习有的放矢,而不至于没了方向.我想告诉大家,现实生活中的问题有哪些类,数学模型就有哪 ...
- CodeForces 484B 数学 Maximum Value
很有趣的一道题,题解戳这. #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)
题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是 ...
- codeforces 484B B. Maximum Value(二分)
题目链接: B. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- TCP/IP状态详解
今天犯懒了,本来自己也做了一些相应的笔记,但是发现这篇写的更好一些,简单易懂,而且有图有真相,为了方便以后查看,在此转载了,在此基础上加了自己的笔记 TCP正常建立和关 ...
- 点聚-weboffice 6.0 (二)
1.修订操作 //设置当前操作用户 function SetUserName() { try{ var webObj=document.getElementById("WebOffice1& ...
- STO到底是什么?
最近,链圈谈论最多的就是STO了,那STO到底是什么?现阶段发展得怎么样? 什么是STO STO英文全称Security Token Offering,即证券化通证发行,指在安全法律体系下受到约束的基 ...
- smartforms 条码打印
转自:http://blog.csdn.net/zhongguomao/article/details/6759642 SAP 条码打印有 新旧 两种技术方法:1.传统的(旧):将数据发送到打印机上, ...
- GstAppSink简介
Description Appsink is a sink plugin that supports many different methods for making the application ...
- 微信小程序开发:学习笔记[7]——理解小程序的宿主环境
微信小程序开发:学习笔记[7]——理解小程序的宿主环境 渲染层与逻辑层 小程序的运行环境分成渲染层和逻辑层. 程序构造器
- linux日常开发使用命令整理
linux: 安装ssh-server:$ sudo apt-get install openssh-server 更新软件库:$ sudo apt-get update 启动ssh:$ sudo / ...
- POJ - 2251 Dungeon Master 【BFS】
题目链接 http://poj.org/problem?id=2251 题意 给出一个三维地图 给出一个起点 和 一个终点 '#' 表示 墙 走不通 '.' 表示 路 可以走通 求 从起点到终点的 最 ...
- manacher小结
P3805 [模板]manacher算法 题目大意 n个字符组成的字符串,求最长回文串 $O$$($$n^3$$)$ 枚举两端点,暴力往中间搜 $O$$($$n^2$$)$ 枚举回文串终点,暴力往两边 ...
- 一篇文章了解相见恨晚的 Android Binder 进程间通讯机制【转】
本文转载自:https://blog.csdn.net/freekiteyu/article/details/70082302 Android-Binder进程间通讯机制 概述 最近在学习Binder ...