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. Function对象

    Function对象是js中很重要的一个元素,js中所有自定义的函数都是Function对象,所以String,Number,Boolean,function等都是Function对象.所以,在使用t ...

  2. [LeetCode] 56. Merge Intervals 解题思路

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  3. MYSQL视图的学习笔记

    MYSQL视图的学习笔记,学至Tarena金牌讲师,金色晨曦科技公司技术总监沙利穆 课程笔记的综合. 视图及图形化工具   1.       视图的定义 视图就是从一个或多个表中,导出来的表,是一个虚 ...

  4. nginx本地的测试环境添加SSL

    要在本地添加SSL,首先要做的是防火墙是不是放开了443端口,同时,在nginx安装时是不是支持了ssl模块,这个安装网上很容易找到相关资料 防火墙,个人还是用iptables比较直观 先将selin ...

  5. SWFLoader交互

    主应用程序: <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx=& ...

  6. C++编程规范之18:尽可能局部地声明变量

    摘要: 避免作用域膨胀,对于需求如此,对于变量也是如此.变量将引入状态,而我们应该尽可能少地处理状态,变量的生存期也是越短越好. 变量的生存期超过必需的长度时会产生以下几个缺点: 1.      它们 ...

  7. javascript实现限制上传文件的大小

    目录 基本思路 示例 [一].基本思路 在FireFox.Chrome浏览器中可以根据document.getElementById(“id_file”).files[0].size 获取上传文件的大 ...

  8. 数据库VIEW(视图)

    视图是基于 SQL 语句的结果集的可视化的表. 视图包括行和列,就像一个真实的表.视图中的字段就是来自一个或多个数据库中的真实的表中的字段. 我们能够向视图加入 SQL 函数.WHERE 以及 JOI ...

  9. java使用ObjectInputStream从文件中读取对象

    import java.io.EOFException;import java.io.FileInputStream;import java.io.FileNotFoundException;impo ...

  10. [RxJS] Observables can throw errors

    Whenever we are writing code, we need to remember that things may go wrong. If an error happens in a ...