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 ...
随机推荐
- CSS篇
一.盒子模型: 标准模式和混杂模式(IE).在标准模式下浏览器按照规范呈现页面:在混杂模式下,页面以一种比较宽松的向后兼容的方式显示.混杂模式通常模拟老式浏览器的行为以防止老站点无法工作. CSS盒子 ...
- Word 宏命令大全
1. 为宏命令指定快捷键.在WORD中,操作可以通过菜单项或工具栏按钮实现,如果功能项有对应的快捷键的话,利用快捷键可以快速实现我们需要的功能.如最常见的CTRL+O.CTRL+A等等.WOR ...
- phpcms 中路径问题
<table width="100%" border="0" cellspacing="0" cellpadding="0& ...
- 部署网站出现System.ServiceModel.Activation.HttpModule错误
1. 部署网站到IIS7.5,Window 2008的时候出现这个错误 2. 错误信息 Server Error in '/' Application. Could not load type 'Sy ...
- RESTFUL API 安全设计指南
RESTFUL API 安全设计指南 xxlegend · 2015/10/18 15:08 0x01 REST API 简介 REST的全称是REpresentational State Trans ...
- white-space: nowrap 与字符串(文本)换行
在需要对字符串进行元素内换行时,我们通常要对该元素设置相关属性约束以及宽度. 例如:style="word-wrap:break-word; word-break: break-all; w ...
- 基础笔记3(二)(专门处理String的正则表达式)
1.常规判断一个字符串是以什么开头,是否是数字的判断方式有: a.通过比较每个字符,注意比较是字符值(ASc码值),不是字面值 String s="); //判断每个字符数组的每个字符 ch ...
- 慕课网__CSS_网页图标制作
参考地址:http://www.flowerboys.cn/font/article/fontsArticle/how-to-turn-your-icons-into-a-web-font.html
- 关于xml配置实现AOP的小知识
除了前面介绍的基于JDK1.5的注解方式来定义切面,切入点和增强处理外,Spring AOP也允许直接使用XML配置文件来管理它们.在JDK1.5之前,只能使用配置文件的方式来管理,在Spring2. ...
- SIGPIPE了解
当未连接成功相机网络,在socket请求中 if (_session->prepareSession("192.168.1.1") != ICH_SUCCEED) // ...