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. HDU_2056——相交矩形的面积

    Problem Description Given two rectangles and the coordinates of two points on the diagonals of each ...

  2. hadoop2.2.0 MapReduce求和并排序

    javabean必须实现WritableComparable接口,并实现该接口的序列化,反序列话和比较方法 package com.my.hadoop.mapreduce.sort; import j ...

  3. shell中的替换

    shell中如果存在一些特殊的字符,就需要进行替换,可进行命令替换.变量替换.转义替换 1.转义字符的替换 shell中包含以下的转移字符 \a   响铃警报\\   反斜杠 \b  退格(删除键) ...

  4. jquery1.7.2的源码分析(六)基本功能

    jQuery.fn.extend({ attr: function( name, value ) { return jQuery.access( this, jQuery.attr, name, va ...

  5. yii 分页 (ajax)

    Controller:class MemberController extends Controller { public function actionmember_list()    {      ...

  6. 面向对象CSS (OOCSS)

    新版 OOCSS 请关注 http://www.oocss.cc/ 时下流行面向对象,那么有没有可能把样式表也面向对象一下呢,将现在的CSS(Cascading Style Sheets层叠样式表)进 ...

  7. 使用GCM服务(Google Cloud Messaging)实现Android消息推送

    最近在网上查了关于很多Android消息推送的资料,其中主要有四种方法. 1) 使用GCM服务(Google Cloud Messaging) 2) 使用XMPP协议(Openfire + Spark ...

  8. C#运行时鼠标移动控件 - 调用Windows API(ReleaseCapture)

    [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern bool SendMes ...

  9. 使用Eclipse生成自动生成apk

    使用Eclipse生成自动生成apk     在eclipse的Preferences -> Android -> Build中有一项“Skip packaging and dexing ...

  10. Intel 被 ARM 逼急了

    英特尔最近推出基于Silvermont架构Bay Trail系列处理器,相对前一代Bonnell架构的最突出的改进就是支持乱序执行 silvermon架构的处理器将出现在pc,平板等: List of ...