Codeforces 890C - Petya and Catacombs 模拟
C. Petya and Catacombs
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute i, he makes a note in his logbook with number ti:
If Petya has visited this room before, he writes down the minute he was in this room last time;
Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute i.
Initially, Petya was in one of the rooms at minute 0, he didn't write down number t0.
At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook?
Input
The first line contains a single integer n (1 ≤ n ≤ 2·105) — then number of notes in Petya's logbook.
The second line contains n non-negative integers t1, t2, ..., tn (0 ≤ ti < i) — notes in the logbook.
Output
In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.
Examples
input
2
0 0
output
2
input
5
0 1 0 1 3
output
3
Note
In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1.
思路:
求问最小的可能房间数目,从后到前遍历,尽量先满足第一条规则,标记为同一房间,直到遇到0停止,进入下一个循环
代码:
#include <bits/stdc++.h>
using namespace std;
int ans[],vis[];
int main() {
memset(vis,,sizeof(vis));
int n,num=;
cin>>n;
for(int i=;i<=n;++i) {
scanf("%d",&ans[i]);
}
for(int i=n;i>=;i--) {
if(vis[i]) continue;
num++;vis[i]=;
int j=i;
while(ans[j]!=||vis[ans[j]]==) {
vis[ans[j]]=;
j=ans[j];
}
}
cout<<num<<endl;
return ;
}
Codeforces 890C - Petya and Catacombs 模拟的更多相关文章
- Codeforces Round #445 C. Petya and Catacombs【思维/题意】
C. Petya and Catacombs time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforce 886C Petya and Catacombs (map,思路)
突然发现百度不到这题的单独题解(果然是因为这是水题么),那我就来写一个了~ 先把题给贴了. C. Petya and Catacombs time limit per test 1 second me ...
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- 【Codeforces Round #445 (Div. 2) C】 Petya and Catacombs
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 看看时间戳为i的点有哪些. 每次优先用已经访问过的点. 如果不行就新创一个点. 注意新创点的时间戳也是i. [代码] #includ ...
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- CodeForces 670 A. Holidays(模拟)
Description On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Ma ...
- Codeforce 886 Технокубок 2018 - Отборочный Раунд 3 C. Petya and Catacombs(结论题)
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really exper ...
随机推荐
- python 模块的概念介绍
模块 模块:本质就是一个.py文件分为三部分:内置模块.第三方模块,自定义模块 模块: 顶层文件 python模块python模块可以将代码量较大的程序分割成多个有组织的.彼此独立但又能互相交互的代码 ...
- makefile学习笔记(一)
1.1:make概述 在linux环境下使用make工具能够比较容易的构建一个属于自己的工程,整个工程的编译只需要一个命令就可以完成编译.连接以至于最后的执行.不过我们需要投入一些时间去学习如何完成m ...
- Android 6.0运行时权限
一.Runtime Permissions Android 6.0在手机安全方面做的一个处理就是增加了运行时权限(Runtime Permissions). 新的权限机制更好的保护了用户的隐私,Goo ...
- JS框架设计读书笔记之-函数
这次写一些函数 1.模拟Object.keys方法 Object.keys = Object.keys || function(obj){ var a = []; // a[0],a[1]...分别赋 ...
- 转载——yum源的超级简单配置
1.先挂载光盘. 使用命令"mount -o loop /dev/sr0 /mnt/cdrom".如果使用命令"mount -o loop /dev/cdrom ...
- java中this关键字解析
由于this关键字在Java程序中经常见到,笔者索性把它的用法总结一下,来和大家一到互相学习一下.总的来说this用在下面几个地方: (1)当局部变量和成员变量同名的时候,需要用this来加以区分 如 ...
- Game of Connections
Game of Connections Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- C# linq创建嵌套组
以下示例演示如何在 LINQ 查询表达式中创建嵌套组. 首先根据学生年级创建每个组,然后根据每个人的姓名进一步细分为小组. public void QueryNestedGroups() { var ...
- null transform hack 强制使用硬件加速
-webkit-transform: translateZ(0); -webkit-transform: translate3d(0,0,0); 作用: 1.切换到硬件合成模式,通常所有事情都CP ...
- jQuery选择器(ID选择器)第一节
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...