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. swoole udp

    server.php <?php $server = new swoole_server('127.0.0.1', 9502, SWOOLE_PROCESS, SWOOLE_SOCK_UDP); ...

  2. QQ群免IDKEY加群PHP源码

    加群链接需要idkey的,该源码自动解析idkey,实现免idkey加群. 该源码来自彩虹秒赞系统. 例如:api.yum6.cn/qqun.php?qun=463631294 <?php /* ...

  3. 面试题之一(Spring和堆栈和逻辑运算符)

    1.&和&&区别? 都是逻辑运算符,都是判断两边同时为真,否则为假:但&&当第一个为假时,后面就不执行,而&则还是要继续执行,直至结束: ——————— ...

  4. SNMP学习笔记之Python的netsnmp和pysnmp的性能对比

    0x00 概览 用python获取snmp信息有多个现成的库可以使用,其中比较常用的是netsnmp和pysnmp两个库.网上有较多的关于两个库的例子. 本文重点在于如何并发的获取snmp的数据,即同 ...

  5. tensorflow mnist 给一张手写字辨别

    https://www.jianshu.com/p/db2afc0b0334 https://blog.csdn.net/xxzhangx/article/details/54563574

  6. 0x30、0x37

    1.write_date(0x30+shi)加0x30是什么意思 答: 将数字0-9转化为字符'0'-'9' 1.write_date(0x37+bai)加0x37是什么意思 答: 将大于9的数字转化 ...

  7. Codeforces 788A Functions again - 贪心

    Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian super ...

  8. tensorflow拟合随机生成的三维数据【学习笔记】

    平台信息:PC:ubuntu18.04.i5.anaconda2.cuda9.0.cudnn7.0.5.tensorflow1.10.GTX1060 作者:庄泽彬(欢迎转载,请注明作者) 说明:感谢t ...

  9. bootstrap的 附加导航Affix导航 (侧边窄条式 滚动监控式导航) 附加导航使用3.

    affix: 意思是粘附, 附着, 沾上. 因此, 附加导航就是 bootstrap的 Affix.js组件. bootstrap的 附加导航, 不是说导航分成主导航, 或者什么 副导航的 而是指, ...

  10. HDU 4734 (数位DP)题解

    思路: dp[pos][pre]代表长度为pos的不大于pre的个数 #include<iostream> #include<cstdio> #include<cstri ...