【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 ...
随机推荐
- Unityclient通信測试问题处理(一)
Unityclient通信測试问题处理(一) 近期在測试程序的通信模块时.遇到了一个问题:Unity的API函数仅仅能在主线程中调用.而作为client程序,我单独启用了一个监听线程来接收服务端发送的 ...
- linux c statfs系统调用
statfs 系统调用原型: int statfs(const char *path, struct statfs *buf); 參数说明: path : 位于须要查询信息的文件系统的路径名(不是设备 ...
- BZOJ 3210 花神的浇花集会 计算几何- -?
题目大意:给定平面上的n个点,求一个点到这n个点的切比雪夫距离之和最小 与3170不同的是这次选择的点无需是n个点中的一个 首先将每一个点(x,y)变为(x+y,x-y) 这样新点之间的曼哈顿距离的一 ...
- 搭建 Docker 环境
- sync---强制将被改变的内容立刻写入磁盘
sync命令用于强制被改变的内容立刻写入磁盘,更新超块信息. 在Linux/Unix系统中,在文件或数据处理过程中一般先放到内存缓冲区中,等到适当的时候再写入磁盘,以提高系统的运行效率.sync命令则 ...
- 洛谷——P2984 [USACO10FEB]给巧克力Chocolate Giving
https://www.luogu.org/problem/show?pid=2984 题目描述 Farmer John is distributing chocolates at the barn ...
- cocoapod卡在了analyzing dependencies
尽管公司的项目没有使用cocoapod,可是有一些第三方库本身依赖其它第三方的库,而且是用cocoapod来管理这些依赖的.所以在使用某些第三方库时.还是须要用到cocoapod的.今天在github ...
- 1.3 Quick Start中 Step 8: Use Kafka Streams to process data官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 8: Use Kafka Streams to process data ...
- Java 批量修改文件后缀
import java.io.*; public class test { public void reName(String path, String from, String to) { File ...
- 《三》Java IO 字节输入输出流
那么这篇博客我们讲的是字节输入输出流:InputStream.OutputSteam(下图红色长方形框内),红色椭圆框内是其典型实现(FileInputSteam.FileOutStream) ...