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. Kali-linux安装之后的简单设置

    1.更新软件源:修改sources.list文件:leafpad /etc/apt/sources.list然后选择添加以下适合自己较快的源(可自由选择,不一定要全部): #官方源deb http:/ ...

  2. 百度Hi之CSRF蠕虫攻击

    漏洞起因:百度是国内最大的中文搜索引擎.同时百度也提供了百度空间.百度贴吧等BLOG社区服务,拥有海量的用户群,号称全球最大中文社区. 80sec发现过百度产品一系列的安全漏洞,其中一些问题得到了有效 ...

  3. 编写单例的 dojo class

    define([ "dojo/_base/declare" ],function( declare ){ var TimeChartService = declare(" ...

  4. xml string 相互转换

    一.使用最原始的javax.xml.parsers,标准的jdk api // 字符串转XMLString xmlStr = /"....../";StringReader sr ...

  5. spring security 构造函数初始化bean思路

    采用有参数的构造方法来解决注入你要的属性例如:public MyInvocationSecurityMetadataSource(RoleService roleService) { this.rol ...

  6. 深入JS第一天:原型和它的小伙伴们(一)

    我在这里不说定义,找点问题,再解决问题. 一.原型 Q1:这样做输出的结果是什么? jQuery= String; jQuery.prototype.say = function () { alert ...

  7. Win7 VMWare 串口通信

    下载安装工具: 1. 如果电脑(笔记本)没有串口接口,则需要使用一个 USB-Serial 转换线,这里使用 prolific usb-serial USB--串口转换线,首先需要在win7上安装对应 ...

  8. 由CAST()函数在.NET1.1和.NET4.0下处理机制不同所引发的BUG

     .NET 1.1版本下使用日期强制转换函数,比如:"select cast(ActionDate as char(7)) as ActionDate  from ST_BookAction ...

  9. Android /data/data/app_file/目录下面安装apk无权限问题

    当识别SDCard的时候 String filePath = null; String state = Environment.getExternalStorageState(); if (state ...

  10. 编程实现LINUX下目录的层层遍历

    /************************************************************************* > File Name: treedir.c ...