http://codeforces.com/contest/359/problem/D

题意:给你n个数,然后找出在[l,r]中有一个数a[j],l<=j<=r,在[l,r]中的所有数都是a[j]的倍数。找出符合这样的r-l最长长度的个数,输出r-l最长长度的个数和长度,然后输出符合的l的序列。

枚举每一个数,然后向左找到l,向右找到r,r-l就是所求的符合一种,这样就可以找到最长的长度

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 300100
using namespace std; int a[maxn];
int n;
int p[maxn]; int main()
{
while(scanf("%d",&n)!=EOF)
{
int s,t;
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
int max1=;
int t1=;
for(int i=; i<=n; )
{
s=i;
t=i;
while(s>=&&a[s]%a[i]==) s--;
while(t<=n&&a[t]%a[i]==) t++;
i=t;
int len=t-s-;
if(len>max1)
{
t1=;
max1=len;
}
if(len==max1)
{
p[t1++]=s+;
}
}
printf("%d %d\n",t1,max1);
for(int i=; i<t1; i++)
{
if(i==) printf("%d",p[i]);
else printf(" %d",p[i]);
}
printf("\n");
}
return ;
}

cf D. Pair of Numbers的更多相关文章

  1. Codeforces 395 D.Pair of Numbers

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #209 (Div. 2) D. Pair of Numbers (模拟)

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. cf359D Pair of Numbers

    Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find ...

  4. CF 55 D. Beautiful numbers

    D. Beautiful numbers 链接 题意: 求[L,R]中多少个数字可以整除它们的每一位上的数字. 分析: 要求模一些数字等于0等价于模它们的lcm等于0,所以可以记录当前出现的数字的lc ...

  5. CodeForces 359D Pair of Numbers (暴力)

    题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素. 析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为 ...

  6. Pair of Numbers

    Codeforces Round #209 (Div. 2) D:http://codeforces.com/contest/359/problem/D 题意:给以一个n个数的序列,然后问你最大的区间 ...

  7. cf Perfect Pair

    http://codeforces.com/contest/318/problem/C #include <cstdio> #include <cstring> #includ ...

  8. 【Codeforces】CF 165 E Compatible Numbers(状压dp)

    题目 传送门:QWQ 分析 很难想到方向,但有方向了就很easy了. 我们如何减少不必要的计算? 如果我们知道了$ 100111 $的相容的数,$ 100101 $的相容数和他是完全一样的. 我们就靠 ...

  9. CF359D:Pair of Numbers——题解

    https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...

随机推荐

  1. java调优随记-java对象大小

    在java中,基本数据类型的大小是固定.但是java对象的大小是不固定的,需要通过计算. 在java中,一个空对象(没有属性和方法的对象)在堆中占用8byte,比如 Object obj = new ...

  2. MKMapView and Zoom Levels: A Visual Guide

    原帖:http://troybrant.net/blog/2010/01/mkmapview-and-zoom-levels-a-visual-guide/ So, how exactly does ...

  3. 【KMP】Oulipo

    KMP算法 求串内匹配数,计数时返回next[]位置. Problem Description The French author Georges Perec (1936–1982) once wro ...

  4. Redis哨兵模式

    Redis-Sentinel redis的哨兵模式 Redis Sentinel 模式简介 Redis-Sentinel是官方推荐的高可用解决方案,当redis在做master-slave的高可用方案 ...

  5. 【初学者常见问题】一脚踏入protected埋下的陷阱

    受保护的(protected)——声明该成员的类的子类可以访问这个类的成员(但有一定的限制),并且,声明该成员的包内部的任何类也可以访问这个成员 protected修饰符参考:http://www.3 ...

  6. OpenCV中OpenCL模块函数

    It currently develop and test on GPU devices only. This includes both discrete GPUs(NVidia,AMD), as ...

  7. 共享IP云主机(VPS)玩转wdcp

    目前国内有不少性能还不错的共享IP VPS,但因为没有独立IP,所以环境配置起来会比较麻烦. 因为本人自己现在用的就是共享IP的vps,所以把一些配置方法分享一下,供大家参考. 首先是系统的选择,根据 ...

  8. JavaScript兼容问题汇总[实时更新]

    印象笔记链接地址:点我查看   遇到问题不断更新中--    [转载请注明出处-HTML5自由者] 

  9. [Angular 2] Async Http

    Async Pipe: The Asynce pipe receive a Promise or Observable as  input and subscribes to the input, e ...

  10. mybatis与spring的整合

    今天是mybatis的最后一天,也是最为重要的一天,mybatis与spring整合,(spring相关知识我会抽一个大的模块进行讲解). 首先加入Spring的依赖 <dependency&g ...