codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)
题意:给一个数组,求其中任取2个元素,大的模小的结果最大值。
一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减。那么lower_bound(kx)的前一个就是最优的值,用它模x更新。一旦最优值是最后一个元素,那么更新完后break;对数组排序完后对每个元素进行如上操作。(跳过1),复杂度为n/2+n/3+......=n(1/2+1/3+......)=nlogn。不过超时了。因为如果数组中全是2,最后一个为99999,复杂度为n/2+n/2+......=n*n/2。因此数组要去重。
乱码:
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon n;
cin>>n;
vector<lon> vct(n);
for(int i=;i<n;++i)
{
cin>>vct[i];
}
sort(vct.begin(),vct.end());
vct.erase(unique(vct.begin(),vct.end()),vct.end());
lon res=,last=;
for(int i=;i<vct.size();++i)
{
if(vct[i]!=)
for(lon j=;;++j)
{//j<(n/(i+2))+100
lon cur=vct[i]*j;
lon pos=lower_bound(vct.begin(),vct.end(),cur)-vct.begin();
--pos;
//if(i==199999)cout<<n<<" "<<pos<<" "<<vct[pos]<<endl;
res=max(res,vct[pos]%vct[i]);
//cout<<i<<" "<<cur<<endl;
if(pos==n-)break;
if(cur>1e6+)break;
}
}
cout<<res<<endl;
return ;
}
codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)的更多相关文章
- Codeforces 484B Maximum Value(高效+二分)
题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...
- Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数
B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/prob ...
- 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 Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- 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的数 维护 ...
随机推荐
- kafka监控工具
Kafka Web Conslole Kafka Manager KafkaOffsetMonitor.
- php array 根据value获取key,in_array()判断是否在数组内实例
php array 根据value获取key,in_array()判断是否在数组内实例 <?php header("Content-type: text/html; charset=u ...
- sql server deadlock跟踪的四种方法
最近写程序常会遇到deadlock victim,每次一脸懵逼.研究了下怎么跟踪,写下来记录下. 建测试数据 CREATE DATABASE testdb; GO USE testdb; CREATE ...
- 为什么采用4~20mA的电流来传输模拟量?(转)
源: 为什么采用4~20mA的电流来传输模拟量?
- 利用脚本kill掉进程, 语法:运行脚本+进程名
下面附上脚本, 权限需要附X执行 #!/bin/sh #pid kill thread for chenglee #if fileformat=dos, update fileformat=unix ...
- 思考卷积神经网络(CNN)中各种意义
原文:https://blog.csdn.net/aimreant/article/details/53145063 思考卷积神经网络(CNN)中各种意义 只是知道CNN是不够,我们需要对其进行解剖, ...
- 瘋子C语言笔记 (string)
1.strstr() 函数 搜索一个字符串在另一个字符串中的第一次出现.找到所搜索的字符串,则该函数返回第一次匹配的字符串的地址:如果未找到所搜索的字符串,则返回NULL. 2.strcat() 函数 ...
- bootstrap3
bs是基于html5和css3的, h5和css3是今后的趋势. html5只是说文档的 "标准"是h5, 但是文档的类型仍然是 html. 所以在写文档类型的时候, 就不能要那个 ...
- luogu P3387 【模板】缩点
题目 好久没法博客了 这次就水个板子题目吧 tarjan缩点之后重新建图 而且边权应该都是正的(要不我怎么能这么轻松水过去) 在新图上记忆化一下就好了 f[i] 表示 开头选i这个点 的 路径最大值 ...
- MacBook PRO蓝牙无法搜索设备
背景 经常把MacBook合上盖子就塞进包里,用时打开盖子就继续操作,偶尔会出现刚刚还在用的罗技蓝牙鼠标,重新打开笔记本后就连接不上了,而且也无法搜索到周边的蓝牙设备. 解决方案 快捷键:Option ...