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 ...
随机推荐
- 什么是hasLayout?
想更好的理解CSS,尤其是IE下对CSS的渲染,hasLayout是一个非常有必要彻底弄清楚的概念,大多数IE下的显示错误,就是源于hasLayout.hasLayout是一种只读属性,有两种状态tr ...
- 微信小程序-视图条件渲染
条件渲染 wx:if 在框架中,我们用 wx:if="{{condition}}" 来判断是否需要渲染该代码块: <view wx:if="{{condition} ...
- Solr内置的字段类型
字段类型在org.apache.solr.schema包下 Class 描述 BCDIntField 二进制整形字段 BCDLongField 二进制长整形字段 BCDStrField 二进制字符型字 ...
- html+js 的一些小问题
html+js 的一些小问题: 选择器+遍历函数: $("#taskStatusList tr:gt(0)").find("td:eq(3)").find(&q ...
- [Android] Google IAP unmaneged items服务器校验
android IAP unmaneged items 服务器校验 当成功IAP以后, 会在google服务器记录此次购买的状态. 可以通过Google Play Android Developer ...
- 元素定义了position:fixed;后怎么居中
div{ position:fixed; width:1200px; margin:0 auto; top:0; bottom:0; left:0; right:0; }
- laravel old
最近做一个laravel框架下的一个网页.遇到了old 无法点击选中的问题,捉摸好久,原来,laravel下的old 是基于seesion下的. 如果想用old必须要在session有的情况下.
- ${param.xxx}获取url中的参数
在项目中看到了一个很奇怪的EL表达式...${param.catid}...一直找不到param在哪里定义的...(主要是水平太屎...) 然后从网上查了一下才知道是啥... EL表达式${param ...
- PPTP协议
PPTP协议 PPTP(Point-to-Point Tunneling Protocol)点对点隧道协议是PPP协议的一种扩展,它将PPP帧封装进IP包中,通过IP网络进行传输.它通过PPTP控制连 ...
- ADO.NET 基础 (SQL Server)
一.Web.config配置 <connectionStrings> <add name="constr_name" connectionString=" ...