Codeforces Round #204 (Div. 2)->B. Jeff and Periods
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
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用来累加符合条件的数,然后就遍历,比较相同数坐标的差值是否是公差,好像没什么解释的了。。。
#include<bits/stdc++.h>
using namespace std;
int main() {
int a[]={}, flag[]={}, p[]={};
int n, x, cnt = ;
cin >> n;
for (int i = ; i <= n; i++) {
cin >> x;
if(flag[x])
continue;
if(a[x]) {
if(p[x] == )
p[x] = i - a[x];
else if(p[x] != i - a[x]) {
flag[x] = ;
cnt--; } } else
cnt++;
a[x] = i;
//cout<<i<<x<<cnt<<endl;
}
cout<<cnt<<endl;
for(int i=;i<=;i++){
if(a[i]&&flag[i]==)
printf("%d %d\n",i,p[i]);
}
return ;
}
Codeforces Round #204 (Div. 2)->B. Jeff and Periods的更多相关文章
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
- 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 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- 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 ...
- Codeforces Round #204 (Div. 2) A.Jeff and Digits
因为数字只含有5或0,如果要被90整除的话必须含有0,否则输出-1 如果含有0的话,就只需考虑组合的数字之和是9的倍数,只需要看最大的5的个数能否被9整数 #include <iostream& ...
- Codeforces Round #204 (Div. 2) C. Jeff and Rounding——数学规律
给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小 考虑小数点后面的数字,如果这些数都非零,则就是 abs(原数小数部分相加-1*n), 多一个0 则 m ...
- Codeforces Round #204 (Div. 2)
D. Jeff and Furik time limit per test 1 second memory limit per test 256 megabytes input standard in ...
随机推荐
- linux中PHP dirname(__FILE__)路径问题解决
近期在给wordpress开发模板功能时发现,直接使用include(“文件名”)的形式调用其他php代码片段时会出现路径错误.之前服务器环境一直都是iis,未曾出现过类似的BUG,但换成linux服 ...
- lua进阶(一)
第一章 概览 1.chunks chunks是一系列语句, lua执行的每一块语句,比如一个文件或者交互模式下的每一行都是一个chunks. 2.全局变量 ...
- Linux学习-0626
6.26 Linux的安装1.下载镜像包.iso,启动时设置光盘的包是安装包,就可以看到完成安装流程 安装CentOS 5.52.安装时分区,swap分区,根分区... Linux管理工具:1.Sec ...
- Win8.1想要卸载openSUSE出现问题(2014.8.15已解决)
用DiskGenius激活C盘后果然好用了!随便用EasyBCD恢复一下就好了 下面再说说安装openSUSE这半周多的问题: 1.如果是NVIDIA和Intel双显卡就不要安装NVIDIA的显卡驱动 ...
- main函数的argc和argv
int main(int argc, char const *argv[]) { printf("argc : %c\n",argc); printf(] ); printf( ...
- ORA-00265: instance recovery required, cannot set ARCHIVELOG
OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...
- hdu 1250 Hat's Fibonacci
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Description A Fibonacci sequence ...
- JavaScript高级程序设计之原型对象
构造函数.原型对象.构造器是一体的关系,同时产生: 实例中的隐藏属性__proto__指向原型对象: 原型对象是这四种关系的纽带. 原型对象是动态的,不论在何处变化,实例中可以立即体现出来. var ...
- golang处理错误的艺术
golang中关键API的调用都会在最后返回err(golang多值返回). 调用者可以选择处理, 或者不处理该err, 或原装返回给上一层的调用者. golang中的err是error类型, typ ...
- Object C学习笔记2-NSLog 格式化输出数据
1 . 几种常用类型变量声明 int i =10; BOOL isShow=YES; BOOL isShow=1; float f = 3.1415926; char a =120; NSString ...