cf B. Jeff and Periods
http://codeforces.com/contest/352/problem/B
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[];
int n;
bool vis[];
int len;
struct node
{
int x,id;
bool operator <(const node &a)const
{
return (x<a.x)||(x==a.x&&id<a.id);
}
} p[],p1[];
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(vis,,sizeof(vis));
int cnt=;
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
p[cnt].x=a[i];
p[cnt++].id=i;
}
sort(p,p+cnt);
bool flag1=false;
int cnt1=;
bool flag2=false;
bool flag3=false;
for(int i=; i<cnt; i++)
{
if(!vis[p[i].x])
{
if(!flag1)
{
flag1=true;
}
else
{
if(!flag2)
{
p1[cnt1].x=p[i-].x;
p1[cnt1++].id=len;
}
}
flag2=false;
flag3=false;
len=;
vis[p[i].x]=true;
}
else
{
if(flag2)continue;
if(!flag3)
{
len=p[i].id-p[i-].id;
flag3=true;
}
else
{
if(p[i].id-p[i-].id!=len)
{
flag2=true;
}
}
}
}
if(!flag2)
{
p1[cnt1].x=p[cnt-].x;
p1[cnt1++].id=len;
}
printf("%d\n",cnt1);
for(int i=; i<cnt1; i++)
{
printf("%d %d\n",p1[i].x,p1[i].id);
}
}
return ;
}
cf B. Jeff and Periods的更多相关文章
- B. Jeff and Periods(cf)
B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 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> ...
- CF352B Jeff and Periods 模拟
One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decide ...
- 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 351B]Jeff and Furik[归并排序求逆序数]
题意: 两人游戏, J先走. 给出一个1~n的排列, J选择一对相邻数[题意!!~囧], 交换. F接着走, 扔一硬币, 若正面朝上, 随机选择一对降序排列的相邻数, 交换. 若反面朝上, 随机选择一 ...
- cf C. Jeff and Rounding
http://codeforces.com/contest/352/problem/C 题意:给予N*2个数字,改变其中的N个向上进位,N个向下进位,使最后得到得数与原来数的差的绝对值最小 对每一个浮 ...
- cf A. Jeff and Digits
http://codeforces.com/contest/352/problem/A #include <cstdio> #include <cstring> #includ ...
随机推荐
- Templates 模板:
Templates 模板: ########################温金 $template wj-flow01,"/data01/applog_backup/winfae_log/ ...
- 2014-08-01 ASP.NET中对SQLite数据库的操作——ADO.NET
今天是在吾索实习的第18天.我主要学习了如何在ASP.NET中对SQLite数据库的操作,其基本操作如下: 添加引用System.Data.SQLite.dll(PS:在网页里面任意找到适合的.NET ...
- HDOJ 1061 Rightmost Digit(循环问题)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- 二叉树后序遍历的非递归算法(C语言)
首先非常感谢‘hicjiajia’的博文:二叉树后序遍历(非递归) 这篇随笔开启我的博客进程,成为万千程序员中的一员,坚持走到更远! 折磨了我一下午的后序遍历中午得到解决,关键在于标记右子树是否被访问 ...
- 有关UITableViewCell的侧滑删除以及使用相关大神框架MGSwipeTableCell遇到的小问题
提起笔,却不知道从何写起了,今天一整天都耗费在了这个可能根本不算是问题的小问题上,至今仍有一种蛋蛋的忧桑..(噢,不是提笔,是键盘手T_T) 表格视图在项目中就像是每日的家常便饭,在cell上添加侧滑 ...
- MyBatis第一个项目示例
1.创建一个Java project,JikeBook 2.添加项目所需的依赖包 如 mybatis-3.2.8.jar,是实现mybatis功能所必需的依赖包 mysql-connector-jav ...
- 项目开发中封装一个BarButtonItem类别-很实用
Encapsulates a TabBarItem--封装一个BarButtonItem类 在我们程序的导航栏的左边或右边一般都会有这样的BarButtonItem,用来界面之间的跳转 如果我们有很多 ...
- 11636 - Hello World! (贪心法)
Problem A Hello World! Input: Standard Input Output: Standard Output When you first made the comput ...
- linux自己主动重新启动tomcat脚本
0.个人标记 caicongyang http://blog.csdn.net/caicongyang 1.脚本retomcat.sh #!/bin/sh pid=`ps aux |grep tomc ...
- 怎么给iOS项目打包
1 首先要选中项目中的真机測试,不要模拟器 ,然后从上边的菜单条中找product watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc29tZXJhaW43 ...