B. Jeff and Periods
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input
  1. 1
    2
output
  1. 1
    2 0
input
  1. 8
    1 2 1 3 1 2 1 5
output
  1. 4
    1 2
    2 4
    3 0
    5 0
Note

In the first test 2 occurs exactly once in the sequence, ergo p2 = 0.

题意:给出有n个数的序列,如果x没有相同的数,就输出x和0,如果有多个x,输出它们坐标的差p[x],这个差是公差(common difference between numbers in the progression)(换句话说,相同的数(>2个)的坐标是等差数列即符合),不是公差的就算数字相同也不符合,比如样例2,1的下标是0 2 4 6,所以它们的p是2,2的下标是1 5,它们的p是4,然而比如6  1 2 2 2 1 1  这个样例,1的坐标是1,5,6,(5-1)!=(6-5),所以1不是,2的坐标的2,3,4,,(3-2)==(4-3),所以2是,即输出为1 2 1;

题解:设三个数组a[](记录下标),flag[](标记符合条件的数),p[](公差),cnt用来累加符合条件的数,然后就遍历,比较相同数坐标的差值是否是公差,好像没什么解释的了。。。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int a[]={}, flag[]={}, p[]={};
  5. int n, x, cnt = ;
  6. cin >> n;
  7. for (int i = ; i <= n; i++) {
  8. cin >> x;
  9. if(flag[x])
  10. continue;
  11. if(a[x]) {
  12. if(p[x] == )
  13. p[x] = i - a[x];
  14. else if(p[x] != i - a[x]) {
  15. flag[x] = ;
  16. cnt--;
  17.  
  18. }
  19.  
  20. } else
  21. cnt++;
  22. a[x] = i;
  23. //cout<<i<<x<<cnt<<endl;
  24. }
  25. cout<<cnt<<endl;
  26. for(int i=;i<=;i++){
  27. if(a[i]&&flag[i]==)
  28. printf("%d %d\n",i,p[i]);
  29. }
  30. return ;
  31. }

Codeforces Round #204 (Div. 2)->B. Jeff and Periods的更多相关文章

  1. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

    http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...

  2. Codeforces Round #204 (Div. 2)->C. Jeff and Rounding

    C. Jeff and Rounding time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

  4. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik

    http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...

  5. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  6. Codeforces Round #204 (Div. 2)->D. Jeff and Furik

    D. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #204 (Div. 2) A.Jeff and Digits

    因为数字只含有5或0,如果要被90整除的话必须含有0,否则输出-1 如果含有0的话,就只需考虑组合的数字之和是9的倍数,只需要看最大的5的个数能否被9整数 #include <iostream& ...

  8. Codeforces Round #204 (Div. 2) C. Jeff and Rounding——数学规律

    给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小 考虑小数点后面的数字,如果这些数都非零,则就是  abs(原数小数部分相加-1*n), 多一个0 则 m ...

  9. Codeforces Round #204 (Div. 2)

    D. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. 一款兼容IE6并带有多图横向滚动的jquery特效

    一款兼容IE6并带有多图横向滚动的jquery特效,自动切换多个图片的jquery特效效果, 为大家分享这个的原因是,这款特效在兼容IE6上面很完美,实用性就广很多了. 适用浏览器:IE6.IE7.I ...

  2. HDFS文件读写流程

    一.HDFS HDFS全称是Hadoop Distributed System.HDFS是为以流的方式存取大文件而设计的.适用于几百MB,GB以及TB,并写一次读多次的场合.而对于低延时数据访问.大量 ...

  3. 容易被忽略的事----sql语句中select语句的执行顺序

    关于Sql中Select语句的执行顺序,一直很少注意这个问题,对于关键字的使用也很随意,至于效率问题,因为表中的数据量都不是很大,所以也不是很在意. 今天在一次面试的时候自己见到了,感觉没一点的印象, ...

  4. Python 初学(一) 标识符

    Python 标识符 在python里,标识符由字母.数字.下划线组成: python中的标识符是区分大小写的: 1)以单下划线开头(_foo)的代表不能直接访问的类属性,需要通过类提供的接口进行访问 ...

  5. linux 修改系统时间

    首先进入/proc/sys/xen,执行以下命令 [root@test]#cd   /proc/sys/xen[root@test]#echo 1 > independent_wallclock ...

  6. NFC Forum : Frequently Asked Questions (NFC 论坛:FAQ)

    NFC for Business What is the NFC Forum? The NFC Forum is a not-for-profit industry organization whos ...

  7. ED/EP系列2《文件结构》

    电子存折/电子钱包应用是为持卡人进行金融交易而设计的一种应用.对于一张金融 IC 卡来说,它可以同时支持电子存折和电子钱包两种应用,也可以只支持其中的一种.卡片上两种应用的存在情况可以由应用类型标识( ...

  8. shell-IF判断

    #!/bin/bash echo "-----------------strat---------------" read -p "Enter a number:&quo ...

  9. EXCLE中快速插入图片

    在excle中怎么快速插入图片呢,一张一张点实在比较麻烦 解决办法: <table><img src="D:\A.png" width="60" ...

  10. SpringMvc中Interceptor拦截器用法

    SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.比如通过它来进行权限验证,或者是来判断用户是否登陆等. 一. 使用场景 1 ...