Codeforces Round #276 (Div. 2)D - Maximum Value(筛法)
就是一种筛法思想的应用。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=;
int n,a[maxn],ans=-;
int main()
{
//freopen("in9.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
if(n==){printf("0\n");return ;}
sort(a,a+n);
for(int i=;i<n-;i++)
{
if(i&&a[i]==a[i-]) continue;
for(int t=a[i]*;t<=a[n-];t+=a[i])
{
int p=lower_bound(a,a+n,t)-a;
ans=max(ans,a[p-]%a[i]);
}
ans=max(ans,a[n-]%a[i]);
}
printf("%d\n",ans);
//fclose(stdin);
//fclose(stdout);
return ;
}
Codeforces Round #276 (Div. 2)D - 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. 1) B. Maximum Value 筛倍数
B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/prob ...
- 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的数 维护 ...
随机推荐
- LeetCode-11-6
1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...
- R&python机器学习之朴素贝叶斯分类
朴素贝叶斯算法描述应用贝叶斯定理进行分类的一个简单应用.这里之所以称之为“朴素”,是因为它假设各个特征属性是无关的,而现实情况往往不是如此. 贝叶斯定理也称贝叶斯推理,早在18世纪,英国学者贝叶斯(1 ...
- npm-folders
npm-folders Executable(可执行程序) 在全局模式下,可执行程序被链接到Unix的{prefix}/bin目录下,或者是Windows的{prefix}目录下. 在本地模式下,可执 ...
- css系列(6)css的运用(二)
本节继续介绍css在html页面重的应用实例. (1)div的border-style属性: none: 无样式 hidden: 除了同表格的边框发生冲突的时候,其它同none dot ...
- QGIS 编译
QGIS 编译 在编译的过程中花费了很长时间,特别是编译Debug版本.release版本的编译可以从晚上找到很多的资料,但是Debug的编译相对较少.在Debug编译的过程中,需要单独build工程 ...
- 在Xcode中使用pch文件
Xcode后面的版本不建议在开发时使用pch文件,但如果仍然需要使用pch文件可以这样配置: 1.用快捷键 [CMD] + N 新建文件,选 iOS下的 other->PCH File 2.p ...
- poj 3468 线段树模板题
#include<iostream> #include<algorithm> #include<stdio.h> using namespace std; #def ...
- javax.mail.MessagingException: Could not connect to SMTP host: smtp.xdf.cn
1.问题描述:关于使用Java Mail进行邮件发送,抛出Could not connect to SMTP host: xx@xxx.com, port: 25的异常可能: 当我们使用Java Ma ...
- linux基础(1)-yum源配置
用linux将近一年了,开始学的东西因为没经常用都忘记了,现在将笔记的东西慢慢整理成自己的博客,也算是看着自己进步.有些东西从他人博客笔记学的,有些是从视频学的,有些是自己填坑积累的. 在linux下 ...
- session共享个人小结
一.需求问题: 如果你的网站是存放在一个机器上,那么是不存在这个问题的,因为会话数据就在这台机器,但是如果你使用了负载均衡把请求分发到不同的机器呢? 这个时候会话id在客户端是没有问题的, 但是如果用 ...