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. jquery 删除table行,该如何解决

    query 删除table行< table >  < tbody >  < tr >  < td > 这行原来就有 </ td >  < ...

  2. JSON自动生成相关类

    开源项目地址:https://jsonclassgenerator.codeplex.com/SourceControl/latest 太好用了,这个

  3. Linux服务器---安装mysql

    安装mysql 1.检测是否已安装mysql [root@localhost bin]# rpm -qa | grep mysql mysql-libs-5.1.71-1.el6.i686 [root ...

  4. 计算概论(A)/基础编程练习1(8题)/3:晶晶赴约会

    #include<stdio.h> int main() { int w; scanf("%d", &w); || w==) { printf("%s ...

  5. Ubuntu 16.04下为Android编译OpenCV 3.2.0 Manager

    http://johnhany.net/2016/07/build-opencv-manager-for-android-on-ubuntu/ 最近想在Android上尝试一下SIFT和SURF匹配算 ...

  6. Linux 系统版本信息

    1.# uname -a   (Linux查看版本当前操作系统内核信息) 2.# cat /proc/version (Linux查看当前操作系统版本信息) 3.# cat /etc/issue  或 ...

  7. C++设计模式 之 “数据结构” 模式:Composite、Iterator、Chain of Resposibility

    "数据结构"模式 常常有一些组件在内部具有特定的数据结构,如果让客户程序依赖这些特定的数据结构,将极大地破坏组件的复用.这时候,将这些特定数据结构封装在内部,在外部提供统一的接口, ...

  8. 函数指针(pointer to function)——qsort函数应用实例

    一,举例应用 在ACM比赛中常使用 stdlib.h 中自带的 qsort 函数,是教科书式的函数指针应用示范. #include <stdio.h> #include <stdli ...

  9. Java位运算实现加减乘除

    一.加法 a+b 举例实现:13+9=22 13+9不考虑进位结果为12 只考虑进位结果为10 和刚好是22. 13二进制为1101,9二进制为1001. 不考虑进位结果为0100.算式为a^b 只考 ...

  10. Git 基础笔记整理1

    Git 官网:http://git-scm.com/ git教程1:http://www.yiibai.com/git/home.html git教程2 :http://www.liaoxuefeng ...