352B - Jeff and Periods

思路:水题,考验实现(implementation)能力,来一波vector[允悲]。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset((a),(b),sizeof(a))
const int N=1e5+;
vector<int>g[N];
vector<int>ans;
bool vis[N]={false}; int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n,a;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a;
if(vis[a])continue;
if(!g[a].size()||g[a].size()==)g[a].pb(i);
else
{
if(i-g[a][g[a].size()-]!=g[a][g[a].size()-]-g[a][g[a].size()-])vis[a]=true,g[a].clear();
else g[a].pb(i);
}
} int cnt=;
for(int i=;i<N;i++)
{
if(g[i].size())
{
cnt++;
ans.pb(i);
}
}
cout<<cnt<<endl;
for(int i=;i<ans.size();i++)
{
cout<<ans[i];
if(g[ans[i]].size()==)cout<<' '<<<<endl;
else cout<<' '<<g[ans[i]][g[ans[i]].size()-]-g[ans[i]][g[ans[i]].size()-]<<endl;
}
return ;
}

Codeforces 352B - Jeff and Periods的更多相关文章

  1. codeforces B. Jeff and Periods 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/B 题目意思:给出一个长度为n的序列   a1, a2, ..., an(序号i,1 <= i ...

  2. 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 ...

  3. B. Jeff and Periods(cf)

    B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces 351D Jeff and Removing Periods(莫队+区间等差数列更新)

    题目链接:http://codeforces.com/problemset/problem/351/D 题目大意:有n个数,每次可以删除掉数值相同并且所在位置成等差数列的数(只删2个数或者只删1个数应 ...

  5. Codeforces 351B Jeff and Furik:概率 + 逆序对【结论题 or dp】

    题目链接:http://codeforces.com/problemset/problem/351/B 题意: 给你一个1到n的排列a[i]. Jeff和Furik轮流操作,Jeff先手. Jeff每 ...

  6. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  7. CodeForces 352C. Jeff and Rounding(贪心)

    C. Jeff and Rounding time limit per test:  1 second memory limit per test: 256 megabytes input: stan ...

  8. codeforces A. Jeff and Rounding (数学公式+贪心)

    题目链接:http://codeforces.com/contest/351/problem/A 算法思路:2n个整数,一半向上取整,一半向下.我们设2n个整数的小数部分和为sum. ans = |A ...

  9. cf B. Jeff and Periods

    http://codeforces.com/contest/352/problem/B #include <cstdio> #include <cstring> #includ ...

随机推荐

  1. excel 批量在一列数据添加单引号以及逗号

    在A列后插入一列B1输入="'"&a1&"'," 然后向下填充 就ok 了 向下填充:选中上方连续单元格,鼠标放在选中区域右下角处(会显示“十” ...

  2. 019-centos的yum用法

    1.检测系统是否已经安装过mysql或其依赖:# yum list installed | grep mysql(当然也可以用 rpm -qa | grep mysql) 2.卸载已经存在的mysql ...

  3. 第一篇 Python图片处理模块PIL(pillow)

    本篇包含:一.Image类的属性:1.Format   2.Mode   3.Size    4.Palette    5.Info                   二.类的函数:1.New   ...

  4. http-equiv制作跳转欢迎页面

    做网站嘛,没有个欢迎页面肿么能忍? 要忽悠下浏览者的嘛. 然后此处省略一万字... 目的:不需要其他的脚本,直接在meta中控制时间,跳转页面 原理很简单: < meta http-equiv= ...

  5. Trove系列(五)—Trove的数据存储管理程序类型和版本管理功能介绍

    功能描述数据存储管理程序(Datastore)类型管理允许Trove的用户从操作者列出的名单中选择数据库存储管理程序和版本.操作者将可以控制数据库存储管理程序的类型,添加一个新的版本并去活一个老版本. ...

  6. python-自定义异常,with用法

    抛出异常 #coding=utf-8 def  exceptionTest(num): if num<0: print "if num<0" raise Excepti ...

  7. php 获取随机数的几个方式

    php 获取随机数的几个方式 1.直接获取从min-max的数,例如1-20:$randnum = mt_rand(1, 20); 2.在一个数组里面随机选择一个(验证码的时候需要字母.数字混合的情况 ...

  8. Thinkphp5 引入第三方类库的方法

    原文链接:http://www.zhaisui.com/article/42.html

  9. CentOS 7 怎样自动连接网络

    https://jingyan.baidu.com/article/19192ad8f7c320e53e570728.html

  10. 20145322何志威 Exp8 Web基础

    20145322何志威 Exp8 Web基础 实践过程记录 一.Apache 1 修改/etc/apache2/ports.conf里的端口为5322后重新开启: 2 可以在浏览器中输入localho ...