【Codeforces Round #445 (Div. 2) C】 Petya and Catacombs
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
看看时间戳为i的点有哪些。
每次优先用已经访问过的点。
如果不行就新创一个点。
注意新创点的时间戳也是i.
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n;
int now = 1, tot = 1;
vector <int> have[N + 10];
int before[N + 10];
int main() {
//freopen("F:\\c++source\\rush_in.txt", "r", stdin);
int n;
scanf("%d", &n);
int x;
scanf("%d", &x);
have[1].push_back(tot);
before[tot] = 1;
for (int i = 2; i <= n; i++) {
scanf("%d", &x);
if (!have[x].empty()) {
now = have[x].back();
have[x].pop_back();
before[now] = i;
have[i].push_back(now);
}
else {
tot++;
have[i].push_back(tot);
before[tot] = i;
}
}
printf("%d\n", tot);
return 0;
}
【Codeforces Round #445 (Div. 2) C】 Petya and Catacombs的更多相关文章
- 【Codeforces Round #445 (Div. 2) D】Restoration of string
[链接] 我是链接,点我呀:) [题意] 给你n个字符串. 让你构造一个字符串s. 使得这n个字符串. 每个字符串都是s的子串. 且都是出现次数最多的子串. 要求s的长度最短,且s的字典序最小. [题 ...
- 【Codeforces Round #445 (Div. 2) B】Vlad and Cafes
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 傻逼模拟 [代码] #include <bits/stdc++.h> using namespace std; cons ...
- 【Codeforces Round #445 (Div. 2) A】ACM ICPC
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 三重循环 [代码] #include <bits/stdc++.h> using namespace std; int ...
- 【Codeforces Round #425 (Div. 2) B】Petya and Exam
[Link]:http://codeforces.com/contest/832/problem/B [Description] *能代替一个字符串(由坏字母组成); ?能代替单个字符(由好字母组成) ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
随机推荐
- [Python] Understand Scope in Python
Misunderstanding scope can cause problems in your application. Watch this lesson to learn how Python ...
- Unity3D:粒子系统Particle System
1. GameObject → Create Other → Particle System. 2. 选中 Particle System,可看到下列屬性: 3.Particle System: ...
- unity 获取物体尺寸
unity3d中获得物体的size 以size的x方向为例 1:gameObject.renderer.bounds.size.x;//这个值的结果真实反应出有MeshRenderer这个组件的 ...
- jquery源码12 offset() : 位置和尺寸的方法
// Back Compat <1.8 extension point jQuery.fx.step = {}; if ( jQuery.expr && jQuery.expr. ...
- jquery11源码 animate() : 运动的方法
{ var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, rfxnum = new RegExp( "^(?:([+-])=|)( ...
- JS中的预解析
js预解析对于很多学习web前端开发的新手们很困扰,总是很难搞懂到底是个什么东西,今天零度就为大家简单的分析一下,争取让大家都明白! 首先,看一下下面的代码: alert(a); var a = 1; ...
- 通过PXE安装Linux实况
通过PXE安装Linux实况 网卡引导操作系统的过程我们可以把它称为PXE(Pre-bootExecutionEnvironment),十几年前,在搞无盘NT时候,我们为了使网卡支持PXE引导要特意购 ...
- cocos2dx——lua自己主动和手动绑定
[自己主动绑定] 參考:http://my.oschina.net/skyhacker2/blog/298397 主要是通过引擎自带的tools/tolua,主要过程例如以下: 1.编写好要导出的c+ ...
- 高速入手ITOO导入-改进导入.xlsx格式
这两天一直在研究师哥的导入,在他的基础上进行了一些改进.这次的改进就是能够导入还有一种格式.xlsx格式的.经过几番调试和看师哥写的底层代码最终知道哪里的问题了. workbook = new HSS ...
- start_kernel----lcokdep_init
void lockdep_init(void) { int i; /* * Some architectures have their own start_kernel() * code which ...