cf D. Pair of Numbers
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的更多相关文章
- Codeforces 395 D.Pair of Numbers
D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
- cf359D Pair of Numbers
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find ...
- CF 55 D. Beautiful numbers
D. Beautiful numbers 链接 题意: 求[L,R]中多少个数字可以整除它们的每一位上的数字. 分析: 要求模一些数字等于0等价于模它们的lcm等于0,所以可以记录当前出现的数字的lc ...
- CodeForces 359D Pair of Numbers (暴力)
题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素. 析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为 ...
- Pair of Numbers
Codeforces Round #209 (Div. 2) D:http://codeforces.com/contest/359/problem/D 题意:给以一个n个数的序列,然后问你最大的区间 ...
- cf Perfect Pair
http://codeforces.com/contest/318/problem/C #include <cstdio> #include <cstring> #includ ...
- 【Codeforces】CF 165 E Compatible Numbers(状压dp)
题目 传送门:QWQ 分析 很难想到方向,但有方向了就很easy了. 我们如何减少不必要的计算? 如果我们知道了$ 100111 $的相容的数,$ 100101 $的相容数和他是完全一样的. 我们就靠 ...
- CF359D:Pair of Numbers——题解
https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...
随机推荐
- Netbeans 学习
1.NetBeans快捷键: 1.完成代码:ctrl+\ //任何地方按下此组合键,均会提示相应的参考字段: 2.错误提示:alt + enter //顾名思义,当系统报错时,按下此组合可以查看系统提 ...
- rsyslog 一重启就会开始同步之前所有通配的日志文件
<pre name="code" class="html">[root@dr-mysql01 zjzc_log]# grep '24/Sep/201 ...
- HDU_1238——最大子串搜索
Problem Description You are given a number of case-sensitive strings of alphabetic characters, find ...
- CURD
CURD是一个数据库技术中的缩写词,一般的项目开发的各种参数的基本功能都是CURD. 它代表创建(Create).更新(Update).读取(Read)和删除(Delete)操作. CURD 定义了用 ...
- java笔记4之比较运算符
/* 比较运算符: ==,!=,>,>=,<,<= 特点: 无论你的操作是简单还是复杂,结果是boolean类型. ...
- Apache HttpComponents Client 4.0快速入门/升级-2.POST方法访问网页
Apache HttpComponents Client 4.0已经发布多时,httpclient项目从commons子项目挪到了HttpComponents子项目下,httpclient3.1和 h ...
- [Angular 2] implements OnInit, OnDestory for fetching data from server
Link: https://angular.io/docs/js/latest/api/core/OnInit-interface.html, https://www.youtube.com/watc ...
- 基本SQL语句练习之SELECT
一.SQL Plus连接sqlplus:以命令行方式连接数据库sqlplusw:以窗口登录方式连接数据库conn sys/password as sysdba;show userselect * fr ...
- 忘记 mysql5.5.24 数据库 root 密码
兹整理如下,供网友参考 第一步:关闭mysql服务 第二步:新建txt 写入如下内容 UPDATE mysql.user SET Password=PASSWORD('blog.const.net.c ...
- 台式电脑部署xen虚拟化的各种问题
本打算用一台台式机做xen虚拟化,搞了一天搞得焦头烂额还是没搞定,中间遇到各种奇葩问题,这里mark一下 1.计划用三块2TB的SATA硬盘,然后装centos5 做虚拟化,结果忘记了centos5最 ...