Codeforces Round #206 div1 C
CF的专业题解 :
The problem was to find greatest d, such that ai ≥ d, ai mod d ≤ k holds for each i.
Let m = min(ai), then d ≤ m. Let consider two cases:

. In this case we will brute force answer from k + 1 to m. We can check, if number d is a correct answer in the following way:
We have to check that ai mod d ≤ k for some fixed d, which is equals to
, where
. Since all these intervals [x·d..x·d + k] doesn't intersects each with other, we can just check that
, where cnt[l..r] — count of numbers ai in the interval [l..r].
我用汉语大体概括一下
对于 k值是大于等于数组里面的最小值a1的时候 那么肯定答案就是a1
else 就暴力枚举可能的答案d 对于可以减去[0-k] 把d整除的区间有 [d,..d+k] [2d..2d+k] [3d..3d+k]等等。。然后可以标记数组里出现的数 数下在这些区间出现的数有多少个 如果等于N 那么就是满足条件的
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define N 300010
#define M 1000000
int a[N],vis[*M+];
int main()
{
int n,i,j,k,ans;
cin>>n>>k;
for(i = ; i <= n ; i++)
{
cin>>a[i];
vis[a[i]]++;
}
sort(a+,a+n+);
for(i = ;i <= M* ;i++)
vis[i] += vis[i-];
if(k>=a[])
{
printf("%d\n",a[]);
return ;
}
for(i = k ; i <= a[n] ; i++)
{
int sum=;
for(j = i ; j <= a[n] ; j+=i)
{
sum+=vis[j+k]-vis[j-];
}
if(sum==n)
ans = i;
}
cout<<ans<<endl;
return ;
}
Codeforces Round #206 div1 C的更多相关文章
- Codeforces Round #543 Div1题解(并不全)
Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...
- Codeforces Round #545 Div1 题解
Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...
- Codeforces Round #539 Div1 题解
Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...
- [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】
题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...
- Codeforces Round #253 DIV1 C 馋
http://codeforces.com/contest/442/problem/C 题意非常easy,基本上肯定有坑坑洼洼的样子.看题目案例,从第三个跟第二个没有凹的案例来看的话,多写几个以及多画 ...
- Codeforces Round #206 (Div. 2) 部分题解
传送门:http://codeforces.com/contest/355 A:水题,特判0 int k,d; int main(){ //FIN; while(cin>>k>> ...
- Codeforces Round #413 (Div1 + Div. 2) C. Fountains(树状数组维护最大值)
题目链接:https://codeforces.com/problemset/problem/799/C 题意:有 c 块硬币和 d 块钻石,每种喷泉消耗硬币或钻石中的一种,每个喷泉有一个美丽值,问建 ...
- Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
#include <iostream> using namespace std; int main(){ int k,d; cin >> k >>d; ) { k ...
随机推荐
- wifi current SSID
1. 引入头,#import <SystemConfiguration/CaptiveNetwork.h> 2. 获取SSID info + (id)fetchSSIDInfo { NSA ...
- 查看Linux下*.a库文件中文件、函数、变量等情况
在Linux 下经常需要链接一些 *.a的库文件,那怎么查看这些*.a 中包 含哪些文件.函数.变量: 1. 查看文件:ar -t *.a 2. 查看函数.变里:nm *.a
- Http Module 介绍
引言 Http 请求处理流程 和 Http Handler 介绍 这两篇文章里,我们首先了解了Http请求在服务器端的处理流程,随后我们知道Http请求最终会由实现了IHttpHandler接口的类进 ...
- BZOJ1083: [SCOI2005]繁忙的都市
水题之王SP…这题就裸的最小生成树 /************************************************************** Problem: 1083 User ...
- lof基金
lof基金 编辑 LOF基金,英文全称是"Listed Open-Ended Fund",汉语称为"上市型开放式基金".也就是上市型开放式基金发行结束后,投资者 ...
- JQuery的ajax方法
1.使用方式: 由于是全局方法,所以调用简单:$.ajax(); 2.可输入参数: 最好是写成一个json形式,个人不建议用链式,那样看上去不太好. 参数名称 类型 描述 dataType strin ...
- Xcode显示行号
- hadoop,spark,linux上常用命令
记下常用命令,慢慢补充 1.hadoop 查看hdfs上的目录: hadoop fs -ls /给hdfs上目录授予权限: hadoop fs -chmod 777 /tmp/hive 在hdfs ...
- Mysql统计总结 - 最近30天,昨天的数据统计
-- 最近30天的医说发布数量SELECT substr(a.feed_publish_time,6, 5) AS '日期', count(*) AS '医说数' FROM xm_feed a WHE ...
- WCF分布式开发步步为赢(7):WCF数据契约与序列化
本节继续学习WCF分布式开发步步为赢(7):WCF数据契约与序列化.数据契约是WCF应用程序开发中一个重要的概念,毫无疑问实现客户端与服务端数据契约的传递中序列化是非常重要的步骤.那么序列化是什么?为 ...