题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素。

析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为r。那么我们下一点考虑r+1即可,

因为[l, r]之间不会有更优解。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<double, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-5;
const int maxn = 3e5 + 10;
const int mod = 1e6;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn]; int main(){
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d", a+i);
int r = 0;
int ans = 0;
vector<int> v;
for(int i = 1; i <= n; i = r){
if(a[i] == 1){
printf("1 %d\n1\n", n-1);
return 0;
}
int l = i; r = i;
while(a[l] % a[i] == 0 && l > 0) --l;
while(r <= n && a[r] % a[i] == 0) ++r;
if(ans < r-l-2){
ans = r-l-2; v.clear();
}
if(ans == r-l-2) v.push_back(l+1);
}
printf("%d %d\n", v.size(), ans);
for(int i = 0; i < v.size(); ++i){
if(i) putchar(' ');
printf("%d", v[i]);
}
printf("\n");
return 0;
}

CodeForces 359D Pair of Numbers (暴力)的更多相关文章

  1. [codeforces] 359D Pair of Numbers

    原题 RMQ st表棵题 要想让一个区间里的所有数都可以整除其中一个数,那么他一定是这个区间内的最小值,并且同时是这个区间的gcd.然后这个问题就转化成了RMQ问题. 维护两个st表,分别是最小值和g ...

  2. Codeforces 359D Pair of Numbers | 二分+ST表+gcd

    题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...

  3. Codeforces 395 D.Pair of Numbers

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

  4. 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 ...

  5. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  6. CodeForces 359D (数论+二分+ST算法)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...

  7. cf359D Pair of Numbers

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

  8. Educational Codeforces Round 23 C. Really Big Numbers 暴力

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. codeforces 9 div2 C.Hexadecimal's Numbers 暴力打表

    C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...

随机推荐

  1. MapReduce框架在Yarn上的具体解释

    MapReduce任务解析 在YARN上一个MapReduce任务叫做一个Job. 一个Job的主程序在MapReduce框架上实现的应用名称叫MRAppMaster. MapReduce任务的Tim ...

  2. Java 多线程1(转载)

    来源:http://hllvm.group.iteye.com/group/wiki/2877-synchronized-volatile 最近想将java基础的一些东西都整理整理,写下来,这是对知识 ...

  3. HTML5学习笔记简明版(9):变化的元素和属性

    改变的元素(Element) 下面元素在HTML5里的使用方法稍作改动以便能在web里更好的使用或者起到更大作用: 没有href属性的a元素将显示成一个占位符,并且a元素内部如今支持flow cont ...

  4. Python: lambda, map, reduce, filter

    在学习python的过程中,lambda的语法时常会使人感到困惑,lambda是什么,为什么要使用lambda,是不是必须使用lambda? 下面就上面的问题进行一下解答. 1.lambda是什么? ...

  5. 九度OJ 1131:合唱队形 (DP、最长上升下降序列)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2865 解决:881 题目描述: N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学不交换位置就能排成合唱队形. ...

  6. java object monitor

    1 什么是java object monitor 每个java对象头中都有锁状态位标记.java中在使用synchronize同步的时候,肯定是涉及到某个对象的锁.因此,在考虑同步的时候,首先要想到是 ...

  7. Pipeline inbound(netty源码7)

    netty源码死磕7  Pipeline 入站流程详解 1. Pipeline的入站流程 在讲解入站处理流程前,先脑补和铺垫一下两个知识点: (1)如何向Pipeline添加一个Handler节点 ( ...

  8. 预料外的变量值的改变是很多bug的源头

  9. Machine Learning in Action(5) SVM算法

    做机器学习的一定对支持向量机(support vector machine-SVM)颇为熟悉,因为在深度学习出现之前,SVM一直霸占着机器学习老大哥的位子.他的理论很优美,各种变种改进版本也很多,比如 ...

  10. vue指令与$nextTick 操作DOM的不同之处

    异步更新队列 可能你还没有注意到,Vue 异步执行 DOM 更新.只要观察到数据变化,Vue 将开启一个队列,并缓冲在同一事件循环中发生的所有数据改变.如果同一个 watcher 被多次触发,只会被推 ...