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. 8.2.1.3 Range Optimization

    8.2.1.3 Range Optimization 范围访问方法使用一个单个的索引来检索表记录的自己,包含在一个或者索引值区间. 它可以用于一个单独的部分或者多个部分的索引,下面章节给出了一个详细的 ...

  2. cursor: pin S

    declare v_sql varchar2(200); begin loop v_sql :='select seq1.nextval from dual'; execute immediate v ...

  3. iOS项目更新之升级Xcode7 & iOS9

    金田 前言      Apple 的WWDC所发布内容在给大家带来惊喜之际,给各位iOS开发的同仁却也带来了不同程度的麻烦.首先不讲新功能,就单指原来老版本的项目升级.代码升级,就是一堆问题,而且是不 ...

  4. MFC界面更新实现方法

    1.更新窗口 即采用UpdateWindow()函数立即发送WM_PAINT消息更新整个窗口. void CEditTestDlg::OnBnClickedBtnSysUpdate() { CStri ...

  5. Palindrome Permutation II 解答

    Question Given a string s, return all the palindromic permutations (without duplicates) of it. Retur ...

  6. 如何修改Oracle用户密码

    大家如果不知道oracle数据库的密码的话,我们可以通过简单的命令行把密码进行修改. 1.打开cmd 2 在弹出的命令提示窗口输入 set oracle_sid=数据库名称(实例),回车.例如数据库名 ...

  7. iframe切换内容页仍然能自适应大小代码(含js)

    function setIframeHeight(iframe) { if (iframe) { var iframeWin = iframe.contentWindow || iframe.cont ...

  8. VC CArchive类使用

    CFile file("D:\\1.txt",CFile::modeCreate | CFile::modeWrite); CArchive ar(&file,CArchi ...

  9. codeforce 437B The Child and Set

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  10. mysql数据库的高可用方法总结

    高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一 些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无 ...