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 ...
随机推荐
- 一个坑:java.sql.ResultSet.getInt==》the column value; if the value is SQL NULL, the value returned is 0
Retrieves the value of the designated column in the current row of this ResultSet object as a String ...
- BZOJ3402: [Usaco2009 Open]Hide and Seek 捉迷藏
3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 51 Solved: 4 ...
- 关于我的FGC的OAuth2.0认证。
这个名字估计很冷门,估计不会有人看到吧,我猜测的. (阅读以下全文之前请先搞定翻^#$%@#墙这件事.昨天看了一个笑话说墙之父方校长说自己有六个VPN账号,只是为了测试自己的墙好用还是VPN好用.哈哈 ...
- codevs1033 蚯蚓的游戏问题
题目描述 Description 在一块梯形田地上,一群蚯蚓在做收集食物游戏.蚯蚓们把梯形田地上的食物堆积整理如下: a(1,1) a(1,2)…a(1,m) a(2,1) a(2,2) a(2 ...
- 使用MapReduce将HDFS数据导入到HBase(二)
package com.bank.service; import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf. ...
- RHEL修改主机名和IP
1, 修改主机名 vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=NEWHOSTNAME #修改该值作为主机名,如:NEWPC ...
- 四、Solr数据源配置(JNDI、DIH)及定时重做索引
简介 Solr支持很多种创建索引的方式,包括网页,xml以及数据库,因为我这边做的是企业级的搜索,所以用的是数据库建立索引.其实从数据库建立索引,很大程度上取决于原来的数据库设计. 从数据库建立索引, ...
- android怎样写一个循环文字滚动的TextView
效果图: 在layout中这样来声明: <com.kaixin001.view.ScrollText android:id="@+id/news_statustxt" and ...
- Mysql数据库里面的String类型依照数字来排序以及按时间排序的sql语句
今天做项目的时候,遇到个小小的问题,在数据库中查询的时候,要用String类型的ID进行一下排序!(注:ID字段为 varchar 类型) 解决的方法: 如: SELECT * FROM Stude ...
- 关于js中 document.body.scrollTop 不能返回正确值的原因
本来是为了通过document.body.scrollTop来获取浏览器垂直滚动条向下滚动的像素,但是不管滚动条在什么位置总是返回是0,造成这样的原因和html的头部声明有关,如果头部声明 为:< ...