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 ...
随机推荐
- nginx入门配置
user www www; worker_processes 4; error_log logs/error.log; #pid logs/nginx.pid; events { worker_con ...
- 设计模式(七):Adapter 适配器模式 -- 结构型模式
1. 概述: 接口的改变,是一个需要程序员们必须(虽然很不情愿)接受和处理的普遍问题.程序提供者们修改他们的代码;系统库被修正;各种程序语言以及相关库的发展和进化. 例子1:iphone4,你即可以 ...
- C++中使用stringstream进行类型转换操作
stringstream包括istringstream和ostringstream,提供读写string的功能,使用时需包含stream文件.4个操作:1. stringstream strm; 创建 ...
- Tradesy | IT桔子
Tradesy | IT桔子 Tradesy www.tradesy.com 认领 关注 分享
- 使用MapReduce将HDFS数据导入到HBase(二)
package com.bank.service; import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf. ...
- vb安装过程中 ntvdm.exe[9696]中发生未处理的win32异常
最近电脑总是出问题导致我的学习效率很低,前几天在用VB6.0的时候有个知识点不太熟悉,于是按F1发现不会出来帮助文档.突然想到重新装系统之后忘记了安装MSDN帮助插件,就在我安装这个软件的时候发现电脑 ...
- windows server2012域服务器降级的方法
最近在一个新的网络环境里建立windows域服务器,准备建立主.备两台域服务器.在一台新服务器上面安装了windows2012R2并配置了DC服务.域和林的级别设置为Windows2012R2级别.在 ...
- 控制反转(IOC)/依赖注入(DI)理解
个人学习笔记,来自Acode. 1.术语 控制反转/反向控制,英文全称“Inversion of Control”,简称IoC. 依赖注入,英文全称“Dependency Injection”,简称D ...
- Java使用poi包读取Excel文档
项目需要解析Excel文档获取数据,就在网上找了一些资料,结合自己这次使用,写下心得: 1.maven项目需加入如下依赖: <dependency> <groupId>org. ...
- 我的SD卡乱码解决方案
转载请注明出处.chendesheng1988是原作者. 问题描述:射频模块读取证件信息后,串口读取的信息存到SD卡,存进去发现汉字是乱码. 解决方案:使用函数WideCharToMultiByte搞 ...