http://codeforces.com/contest/355/problem/E

每个数都可以变成段 [a-k,a], 某一个因子是否被所有的段包含,就是把这个因子以及它的所有倍数看成点,

看是不是所有的段包含点

假如说所有的 a-k都大于0 那么最小的 k+1这个因子一定是所有段都包含的

如果有的段被0截断了(a-k不大于0)那么所有段都包含的最大因子就是最小段(0,a)的 a

假如所有段都没有被截断,最小可能解是k+1, 然后依次向上枚举 对于所有大于k的因子,每一个段要么包含一个点,要么不包含点

把所有的段在数组上标记,这样很快就可以判定一个因子是不是被所有的段包含了

代码:

#include<iostream>
#include<stack>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<cmath> using namespace std; typedef long long ll;
typedef pair<int,int> pp;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int N=1000005;
int d[N];
int main()
{
//freopen("data.in","r",stdin);
int n,k;
while(cin>>n>>k)
{
memset(d,0,sizeof(d));
int m=INF;
for(int i=0;i<n;++i)
{
int l,r;
cin>>r;
m=min(m,r);
if(m<=k+1) continue;
l=r-k;
++d[l];--d[r+1];
}
if(m<=k+1)
cout<<m<<endl;
else
{
for(int i=1;i<=1000000;++i)
d[i]+=d[i-1];
int ans=k+1;
for(int i=k+2;i<=1000000;++i)
{
int num=0;
for(int j=i;j<=1000000;j+=i)
num+=d[j];
if(num==n)
ans=i;
}
cout<<ans<<endl;
} }
return 0;
}

E. Vasya and Beautiful Arrays的更多相关文章

  1. Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)

    Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...

  2. Codeforce 57C Array

    C. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  3. Restoring Numbers

                                                                                  D. Restoring Numbers   ...

  4. codeforces 57 C Array(简单排列组合)

    C. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  5. D. Vasya and Arrays

    链接 [http://codeforces.com/contest/1036/problem/D] 题意 给你两个数组长度分别为n,m; 有这么一种操作,用某个数组的某个子区间元素之和代替这个子区间, ...

  6. CF1036D Vasya and Arrays 题解

    Content 给定两个长度分别为 \(n\) 和 \(m\) 的数列 \(A,B\).你需要将两个数列都恰好分成 \(k\) 份,使得两个数列中第 \(i(i\in[1,k])\) 份的元素和对应相 ...

  7. Ural1387 Vasya's Dad

    Description Vasya's dad is good in maths. Lately his favorite objects have been "beautiful" ...

  8. Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]

    题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...

  9. 20155312张竞予 20170510实践一:在IDEA中以TDD的方式对String类和Arrays类进行学习

    实践题目 在IDEA中以TDD的方式对String类和Arrays类进行学习 测试相关方法的正常,错误和边界情况 String类 charAt split Arrays类 sort binarySea ...

随机推荐

  1. JavaScript的chapterII

    程序流程控制: 1.条件语句——if     if(condition) {statement1}     else {statement2} 例子:     if(i<60 && ...

  2. srand()以及rand()函数用法

    srand()就是给rand()提供种子seed 如果srand每次输入的数值是一样的,那么每次运行产生的随机数也是一样的, srand(n) for(10) rand()也就是说,以一个固定的数值作 ...

  3. SQL出错

    2016-12-26 15:43:02,870 DEBUG [org.springframework.test.context.support.DirtiesContextTestExecutionL ...

  4. Gradle版本变更的问题

    了解相关三个概念 gradle .gradle wrapper . gradle plugin (1)Gradle  :  项目的构建工具,管理一个项目的依赖架包.性质和maven相似. (2)Gra ...

  5. vs visual studio 让外网访问设置

    vs2015 提供外网访问我是这么解决的 有时我们经常会用到连接外网的方式来调试自己写的莫名bug.而我们通常有两种解决方式 一.捕捉错误日志进行代码分析. 二.则是将我们的源码项目提供外网访问进行直 ...

  6. ListView下拉加载一(分页)

    首先创建在主xml里放置一个listview列表,代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...

  7. boost字符串算法

    boost::algorithm简介 2007-12-08 16:59 boost::algorithm提供了很多字符串算法,包括: 大小写转换: 去除无效字符: 谓词: 查找: 删除/替换: 切割: ...

  8. <mvc:annotation-driven/>与<context:annotation-config/>的区别

    在使用注解的方式配置SSM的时候一般会配置<mvc:annotation-driven/>与<context:annotation-config/>,有时候会对两者的概念有些区 ...

  9. VB调用sendinput API

    http://files.cnblogs.com/files/liuzhaoyzz/VB%E8%B0%83%E7%94%A8sendinput_API.rar sendinput只支持发送字符或者组合 ...

  10. neatbean 8+版本 配置

    //更改代码行距 打开C:\Users\{yourname}\AppData\Roaming\NetBeans\7.3.1\config\Editors\Preferences,用文本编辑器打开 or ...