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 ...
随机推荐
- php 随机显示图片的函数(实例分享)
转自:http://www.jbxue.com/article/12695.html 发布:thatboy 来源:Net [大 中 小] 本文分享一个php实现的随机显示图片的函数,可以将 ...
- 《安全参考》HACKCTO-201311-11
小编的话 “晴空一鹤排云去,便引诗情到碧宵” 11月是一个让人思绪飞扬.感慨万千的时节. 就在这时,在我们小伙伴的并肩奋战下,第十一期<安全参考>又跟大家见面了. 你还在为女朋友在购物狂欢 ...
- Creating an API-Centric Web Application[转]
Creating an API-Centric Web Application 转自 http://hub.tutsplus.com/tutorials/creating-an-api-centric ...
- onClick事件实现方式(打电话为例子)
1.在button 中 android:onclick="call" 注意事项:①.方法的名字必须是call ②.区别大小写 ③.call方法必须接收一个View类型的参数 ④.方 ...
- WinSock编程基础
一.套接字模式 1.阻塞模式 创建套接字时,默认是阻塞模式,对recv函数调用会使程序进入等待状态,知道接收到数据才返回. 2.非阻塞模式: 可以调用ioctlsocke ...
- 关键字替换排除HTML标签属性字符
解决办法: 1.打开文件e/class/functions.php 2.找到函数 ReplaceKey($newstext,$classid=0) 3.找到替换代码 if(STR_IREPLACE) ...
- SQLite中命令行程序(CLP)的使用
SQLite CLP是使用和管理SQLite数据库最常用的工具.它在所有平台上的操作方式相同.CLP其实是两个程序,它可以运行在Shell模式下以交互的方式执行查询操作,也可以运行在命令行模式下完成各 ...
- 关于iphone消息推送把C#当服务器端来发送
看了苹果消息推送文档,感觉推送很简单的,但是还是按个人习惯把这些简单知识记录下来,在需要时候再查看一下! 在开发之前,要准备以下的资料 1.证书(包括产生证书和调试证书) 2.证书密码 3.唯一标识( ...
- [terry笔记]Oracle会话追踪(二):TKPROF
接上一笔记[terry笔记]Oracle会话追踪(一):SQL_TRACE&EVENT 10046 http://www.cnblogs.com/kkterry/p/3279282.html ...
- Moses 里的参数(未完成)
老师要求看看Moses里都有什么参数,调整了参数又会对翻译结果有什么影响,先将找到的参数列出来 首先是权重: [weight] WordPenalty0= LM= Distortion0= Phras ...