CF的专业题解 :

The problem was to find greatest d, such that ai ≥ d,  aimodd ≤ 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 aimodd ≤ 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的更多相关文章

  1. Codeforces Round #543 Div1题解(并不全)

    Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...

  2. Codeforces Round #545 Div1 题解

    Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...

  3. Codeforces Round #539 Div1 题解

    Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...

  4. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  5. [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】

    题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...

  6. Codeforces Round #253 DIV1 C 馋

    http://codeforces.com/contest/442/problem/C 题意非常easy,基本上肯定有坑坑洼洼的样子.看题目案例,从第三个跟第二个没有凹的案例来看的话,多写几个以及多画 ...

  7. Codeforces Round #206 (Div. 2) 部分题解

    传送门:http://codeforces.com/contest/355 A:水题,特判0 int k,d; int main(){ //FIN; while(cin>>k>> ...

  8. Codeforces Round #413 (Div1 + Div. 2) C. Fountains(树状数组维护最大值)

    题目链接:https://codeforces.com/problemset/problem/799/C 题意:有 c 块硬币和 d 块钻石,每种喷泉消耗硬币或钻石中的一种,每个喷泉有一个美丽值,问建 ...

  9. Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    #include <iostream> using namespace std; int main(){ int k,d; cin >> k >>d; ) { k ...

随机推荐

  1. 各大公司广泛使用的在线学习算法FTRL详解

    各大公司广泛使用的在线学习算法FTRL详解 现在做在线学习和CTR常常会用到逻辑回归( Logistic Regression),而传统的批量(batch)算法无法有效地处理超大规模的数据集和在线数据 ...

  2. UML快速指南(摘要)转载

    UML 概述: UML是一个通用的建模语言.它最初开始捕捉到复杂的软件和非软件系统的行为,现在它已经成为一个OMG标准. UML提供元素和组件的复杂系统支持的要求. UML遵循面向对象的概念和方法.因 ...

  3. WPF 详解模板

    在WPF中有三大模板 ControlTemplate,ItemsPanelTemplate,DataTemplate.其中ControlTemplate和 ItemsPanelTemplate是控件模 ...

  4. ASP.NET MVC 从IHttp到页面输出

    MVCHandler应该算是MVC真正开始的地方.MVCHandler实现了IHttpHandler接口,ProcessRequest便是方法入口. MVCHandler : IHttpHandler ...

  5. 解决IE不支持position:fixed问题

    #box { /* 非IE6浏览器使用固定元素 */ position:fixed; top:0; left:0; /* IE6改为绝对定位,并通过css表达式根据滚动位置更改top的值 */ _po ...

  6. 远程数据源Combobox

    Ext.define('bookInfo', {          extend: 'Ext.data.Model',//新类继承自model          fields: [{ name: 'b ...

  7. DevExpress licenses.licx 问题

    在DevExpress ( 当然并不范指DevExpress,很多收费软件都是这样的)中,licenses.licx 是用户许可证书文件,当我们使用某些ActiveX(是Microsoft对于一系列策 ...

  8. JSONObject 包的依赖

    commons-lang.jar commons-beanutils.jar commons-collections.jar commons-logging.jar ezmorph.jar json- ...

  9. UVA 10673 扩展欧几里得

    题意:给出x 和k,求解p和q使得等式x = p[x / k] + q [ x / k], 两个[x / k]分别为向下取整和向上取整 题解:扩展欧几里得 //meek///#include<b ...

  10. Struts2 直接返回字符串(可用于json)

    struts2可以在method中直接返回一个字符串而不是视图.让Action中的返回字符串的方法,直接return null;并在return之前用输出流输出字符串就可以了,跟servlet输出HT ...