E. Vasya and Beautiful Arrays
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的更多相关文章
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- Codeforce 57C Array
C. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Restoring Numbers
D. Restoring Numbers ...
- codeforces 57 C Array(简单排列组合)
C. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- D. Vasya and Arrays
链接 [http://codeforces.com/contest/1036/problem/D] 题意 给你两个数组长度分别为n,m; 有这么一种操作,用某个数组的某个子区间元素之和代替这个子区间, ...
- CF1036D Vasya and Arrays 题解
Content 给定两个长度分别为 \(n\) 和 \(m\) 的数列 \(A,B\).你需要将两个数列都恰好分成 \(k\) 份,使得两个数列中第 \(i(i\in[1,k])\) 份的元素和对应相 ...
- Ural1387 Vasya's Dad
Description Vasya's dad is good in maths. Lately his favorite objects have been "beautiful" ...
- 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 ...
- 20155312张竞予 20170510实践一:在IDEA中以TDD的方式对String类和Arrays类进行学习
实践题目 在IDEA中以TDD的方式对String类和Arrays类进行学习 测试相关方法的正常,错误和边界情况 String类 charAt split Arrays类 sort binarySea ...
随机推荐
- ubantu14下vim的配置...
日出江花红胜火,春来江水绿如蓝.---
- 特殊符号 && 和 ||
一.值为false的情况 如果逻辑对象值为0,-0, null,undefined,false,"",NaN.那么值为false. 二.&& || 的 理解 1.& ...
- requirejs加载css样式表
1. 在 https://github.com/guybedford/require-css 下载到require-css包 2. 把css.js或者css.min.js复制到项目的js目录下 3. ...
- 【Android】解决新建的xml文件无法正常加载的问题
新建一个xml布局文件,如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xm ...
- OpenCV从入门到放弃系列之——如何扫描图像、利用查找表和计时
目的 如何遍历图像中的每一个像素? OpenCV的矩阵值是如何存储的? 如何测试我们所实现算法的性能? 查找表是什么?为什么要用它? 测试用例 颜色空间缩减.具体做法就是:将现有颜色空间值除以某个输入 ...
- Codeforces 722C. Destroying Array
C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...
- angularjs指令系统系列课程(5):控制器controller
这一节我们来说一下controller这个参数 一.指令控制器的配置方法: 对于指令我有两种配置路由的方式:1.在html中直接引用,2,在指令的controller参数里定义 第一种:在html中直 ...
- CentOS 6.3 安装过程
1.放入光盘 2.安装欢迎界面 进入安装欢迎界面,有四个选项: 1.“Install or upgrade an existing system”:安装或升级现有系统 2. “Install syst ...
- 在tomcat中配置jdk的不同版本
在tomcat中配置jdk的不同版本---------------------------------------------------------------------------------- ...
- 使用SQL语句查询每张表的column name
exec sp_columns tableName 上面这行代码可以查出该表所有的column,改为sp_pkeys,可以查出该表的主键.但是我如果想只查出column name,select COL ...