Codeforces 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的更多相关文章
- codeforces B. Jeff and Periods 解题报告
题目链接:http://codeforces.com/problemset/problem/352/B 题目意思:给出一个长度为n的序列 a1, a2, ..., an(序号i,1 <= i ...
- 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 ...
- B. Jeff and Periods(cf)
B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 351D Jeff and Removing Periods(莫队+区间等差数列更新)
题目链接:http://codeforces.com/problemset/problem/351/D 题目大意:有n个数,每次可以删除掉数值相同并且所在位置成等差数列的数(只删2个数或者只删1个数应 ...
- Codeforces 351B Jeff and Furik:概率 + 逆序对【结论题 or dp】
题目链接:http://codeforces.com/problemset/problem/351/B 题意: 给你一个1到n的排列a[i]. Jeff和Furik轮流操作,Jeff先手. Jeff每 ...
- codeforces A. Jeff and Digits 解题报告
题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...
- CodeForces 352C. Jeff and Rounding(贪心)
C. Jeff and Rounding time limit per test: 1 second memory limit per test: 256 megabytes input: stan ...
- codeforces A. Jeff and Rounding (数学公式+贪心)
题目链接:http://codeforces.com/contest/351/problem/A 算法思路:2n个整数,一半向上取整,一半向下.我们设2n个整数的小数部分和为sum. ans = |A ...
- cf B. Jeff and Periods
http://codeforces.com/contest/352/problem/B #include <cstdio> #include <cstring> #includ ...
随机推荐
- 在liferay中如何使用Ajax的请求
1:首先在界面上写一个路径,这个路径就是要找后台中的哪一个操作比如:
- python 四种方法修改类变量,实例对象调用类方法改变类属性的值,类对象调用类方法改变类属性的值,调用实例方法改变类属性的值,直接修改类属性的值
三种方法修改类变量,实例对象调用类方法改变类属性的值,类对象调用类方法改变类属性的值,调用实例方法改变类属性的值,类名就是类对象,city就是类变量, #coding=utf-8 class empl ...
- nodejs中req.body对请求参数的解析问题
首先,先了解一下关于http协议里定义的四种常见数据的post方法,分别是: application/www-form-ulrencoded multipart/form-data applicati ...
- Linux基础命令---paste
paste 将指定的文件按照列的方式合并,将结果显示到标准输出设备上,相当于两个并列的cat命令. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.F ...
- python之路----模块与序列化模块
认识模块 什么是模块 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用pyt ...
- ELK学习笔记之Logstash详解
0x00 Logstash概述 官方介绍:Logstash is an open source data collection engine with real-time pipelining cap ...
- Linux 虚拟机安装vmware tools
Linux Vmware tools安装步骤 1 在 vSphere Client 清单中,右键单击虚拟机,然后选择电源 > 开启. 2 单击控制台选项卡以确定客户机操作系统启动成功,并在需 ...
- 利用Python网络爬虫爬取学校官网十条标题
利用Python网络爬虫爬取学校官网十条标题 案例代码: # __author : "J" # date : 2018-03-06 # 导入需要用到的库文件 import urll ...
- lambda表达式Bug——修改捕获变量失败
解<C++ Primer 5th>的 9-50 练习题时,遇到了 lambda表达式值捕获和引用捕获之区别问题. 欲修改捕获的变量 sum,累加之.但当时忘记值捕获和引用捕获是有区别的.下 ...
- VC++开机自动启动程序的几种方法 (转载)
转载:http://blog.csdn.net/zhazhiqiang/article/details/51909703 很多监控软件要求软件能够在系统重新启动后不用用户去点击图标启动项目,而是直接能 ...