B. Jeff and Periods(cf)
1 second
256 megabytes
standard input
standard output
One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold:
- x occurs in sequence a.
- Consider all positions of numbers x in the sequence a (such i, that ai = x). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all x that meet the problem conditions.
The first line contains integer n (1 ≤ n ≤ 105). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 105). The numbers are separated by spaces.
In the first line print integer t — the number of valid x. On each of the next t lines print two integers x and px, where x is current suitable value, px is the common difference between numbers in the progression (if x occurs exactly once in the sequence, px must equal 0). Print the pairs in the order of increasing x.
1
2
1
2 0
8
1 2 1 3 1 2 1 5
4
1 2
2 4
3 0
5 0
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
const int Max=;
using namespace std;
int main()
{
int n,x;
int vis[Max],p[Max];
while(~scanf("%d",&n))
{
int k = ,i,j;
vector<int>G[Max];
memset(vis,,sizeof(vis));
for (i = ; i < n; i++)
{
scanf("%d",&x);
G[x].push_back(i);//将所有x的位置存入vector中
if (!vis[x])
{
vis[x] = ;
p[k++] = x;
} }
int cnt = ;
memset(vis,-,sizeof(vis));
for (j = ; j < k; j++)
{
int len = G[p[j]].size();
if (len==)
{
++cnt;
vis[p[j]]= ;
continue;
}
int d = G[p[j]][]-G[p[j]][];//求公差
for (i = ; i < len; i++)
{
if (G[p[j]][i]-G[p[j]][i-]!=d)
break;
}
if (i >= len)//说明p[j]的各位置是等差数列
{
++cnt;
vis[p[j]] = d;//表示p[j]各位置的公差为d
}
}
printf("%d\n",cnt);
sort(p, p+k);
for (i = ; i < k ; i++)
{
if (vis[p[i]]!=-)
{
printf("%d %d\n",p[i],vis[p[i]]);
}
}
}
return ;
}
B. Jeff and Periods(cf)的更多相关文章
- Codeforces Round #204 (Div. 2)->B. Jeff and Periods
B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 352B - Jeff and Periods
352B - Jeff and Periods 思路:水题,考验实现(implementation)能力,来一波vector[允悲]. 代码: #include<bits/stdc++.h> ...
- cf B. Jeff and Periods
http://codeforces.com/contest/352/problem/B #include <cstdio> #include <cstring> #includ ...
- CF352B Jeff and Periods 模拟
One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decide ...
- A. Jeff and Digits(cf)
A. Jeff and Digits time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- codeforces B. Jeff and Periods 解题报告
题目链接:http://codeforces.com/problemset/problem/352/B 题目意思:给出一个长度为n的序列 a1, a2, ..., an(序号i,1 <= i ...
- code forces Jeff and Periods
/* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
随机推荐
- ubuntuKylin17.04重装KDE
不小心安装了一个不知道什么的东西,把libROS的那一套都给卸载了,然后删除掉了KDE的很多库.然后KDM也丢失了.KDE界面启动之后,plasma-desktop界面也启动不了.选择重装. 然而出现 ...
- PAT_A1003#Emergency
Source: PAT A1003 Emergency (25 分) Description: As an emergency rescue team leader of a city, you ar ...
- 发现是在IE6-IE9下,下列元素table,thead,tfoot,tbody,tr,col,colgroup,html,title,style,frameset的innerHTML属性是只读的
table ID="zhutiTable" html2="<tr></tr>": 的数据 setTableInnerHTML(docu ...
- [HDU5807] Keep In Touch
\(Keep\ In\ Touch\):保持联络 \(Informatik\ verbindet\ dich\ und\ mich.\) 信息将你我连结? 发现这个方程很容易列出来. \(f[i][j ...
- centos中安装jdk
1.上传jdk安装文件到根目录 2.解压到相关目录 (1)创建相应目录mkdir -p /usr/local/java (2)解压 tar -zxvf jdk-7u80-linux-x64.tar.g ...
- HTML学习笔记之标签基础
目录 1.基本标签 2.链接 3.图像 4.表格 5.列表 6.块与布局 1.基本标签 (1)标题与段落 标签 <h1> ~ <h6> 分别用于定义一至六级标题,标签 < ...
- 利用WMITool解决浏览器快捷方式启动参数被篡改以及浏览器主页被劫持的问题
先说说症状 症状①:通过快捷方式启动浏览器,首页跳转到2345以及hao123网址导航页,切系统内安装的多款浏览器(IE.Chrome.Firefox.Opera.Safari.Maxthon)症状相 ...
- python爬虫19 | 遇到需要的登录的网站怎么办?用这3招轻松搞定!
你好 由于你是游客 无法查看本文 请你登录再进 谢谢合作 当你在爬某些网站的时候 需要你登录才可以获取数据 咋整? 莫慌 小帅b把这几招传授给你 让你以后从容应对 那么 接下来就是 学习 python ...
- svn 使用TortoiseSVN server搭建本地SVN服务器
使用TortoiseSVN server搭建本地SVN服务器
- 【3】数据筛选2 - requests
目录 1.概述 2.下载安装 3.入门程序 4.请求对象:请求方式 5.请求对象:GET参数传递 6.请求对象:POST参数传递 7.请求对象: ...