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的数 维护 ...
随机推荐
- Linux服务器配置---tftpserver
安装tftp-server 1.安装tftp-server [root@localhost weijie]# yum install -y tftp-server Loaded plugins: fa ...
- Linux基础命令---ziinfo
zipinfo 在不解压的情况下,获取zip压缩文件的的详细信息.zipinfo列出了ZIP档案中有关文件的技术信息,最常见的是在MS-DOS系统上.这些信息包括文件访问权限.加密状态.压缩类型.版本 ...
- JS四舍五入保留两位小数
//四舍五入保留2位小数(若第二位小数为0,则保留一位小数) function keepTwoDecimal(num) { var result = parseFloat(num); if (isNa ...
- c++的class声明及相比java的更合理之处
或许是基于一直以来c/c++头文件声明和cXX实现物理上置于独立文件的考虑,c++中的OO在现实中基本上也是按照声明和实现分离的方式进行管理和编译,如下所示: Base.h #pragma once ...
- 20145127 《Java程序设计》第一周学习总结
通过第一周的Java程序设计的学习,听了娄老师的第一堂课,虽然课堂上老师并没有一开始就讲许多专业的知识,而是带领着我们对于Java这门语言,并不仅仅是一门语言,经行了初步的认识与了解,并且对于Java ...
- SPOJ Hacking(字典树 + 搜索)题解
思路1:字典树存每个串,然后dfs遍历是否存在.这里有个技巧,如果每次都重新初始化字典树为-1,那么会超时,所以我先初始化为-1,然后设一个Case,每个test时Case都++,那么只要开一个数组判 ...
- 关于 Local feature 和 Global feature 的组合
关于 Local feature 和 Global feature 的组合 1.全局上下文建模:
- 论文笔记——Deep Model Compression Distilling Knowledge from Noisy Teachers
论文地址:https://arxiv.org/abs/1610.09650 主要思想 这篇文章就是用teacher-student模型,用一个teacher模型来训练一个student模型,同时对te ...
- axis2框架用wsdl文件生成的服务端MessageReceiveInOut文件注意事项
在用axis2生成服务端文件和客户端文件,当客户端文件调用服务端文件时,都是通过wsdl文件生成的 配置文件进行相互的调用. 在一开始做开发测试的时候,通过soapUI进行调用接口的时候,可以调用成功 ...
- 【转载】非Lumia 950/XL机型 强行开启continuum教程
听说Windows 10 Mobile 的 Continuum 特性很长时间了,但是由于我自己的 Lumia 930 不在支持之列,一直没能体验到这个功能.今天在酷七看到了这篇文章,按文章所述的步骤进 ...