codeforces 889A
1 second
256 megabytes
standard input
standard 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?
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.
In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.
2
0 0
2
5
0 1 0 1 3
3
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.
题意:
地下墓穴有很多房间和房间之间的双向通道,探险家在里面探索房间。如果到了之前来过的房间,探险家会在记录一个数字t,t是他上次到这个房间记录的时间,如果这个房间他没来过他就会标记一个当前时间i小的t。通过这些他记录下来的时间t,让你求出最少房间的可能。
思路:
乍一看很复杂,但是题目线索给的很清晰了,一个房间记录的t有两种可能:1.上次来过t是上一次到达这个房间的时间。2.没来过这个房间,t是小于当前时间的一个数字,想让房间最少,当然是尽量选择第一种可能啊。
如果每次都是访问之前到达过的房间的话,是不会有相同的值出现的,一开始会在1个房间,此时时间为0s,如第一个样例: 0 0 ,第一个0代表0秒在的房间,设为房间1 ,第二个0,就不能代表0s在的房间了,因为0s是在1房间,但1房间上一次访问是1s时,1房间记录的应该是1。矛盾了,所以只能是第二种可能,未到过的房间,0是小于当前时间i的随机数。
实现代码:
#include<bits/stdc++.h>
using namespace std; int main()
{
int n,ans,i,a[],b[];
scanf("%d",&n);
ans = ;
memset(b,,sizeof(b));
for(i=;i<=n;i++)
scanf("%d",&a[i]);
for(i=;i<=n;i++){
if(!b[a[i]])
b[a[i]]=;
//cout<<a[i]<<endl;
else ans++;
}
cout<<ans<<endl;
}
codeforces 889A的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- USB主机控制器ECHI
USB主机控制器ECHI 2017年10月24日 15:44:11 阅读数:239 1. 主机控制器(Host Controller) • UHCI: Universal Host Controlle ...
- Linux下端口被占用确认
有时候关闭软件后,后台进程死掉,导致端口被占用.下面以JBoss端口8083被占用为例,列出详细解决过程. 解决方法: 1.查找被占用的端口 netstat -tln netstat -tln | g ...
- Windows Server2003 IIS服务器安全配置整理
一.系统的安装 1.按照Windows2003安装光盘的提示安装,默认情况下2003没有把IIS6.0安装在系统里面.2.IIS6.0的安装 开始菜单—>控制面板—>添加或删除程序—& ...
- Tomcat 动态数据库连接池
package com.boguan.bte.util; import java.sql.Connection;import java.sql.SQLException;import java.uti ...
- 20155339 Exp3 免杀原理与实践
20155339 Exp3 免杀原理与实践 基础问题 (1)杀软是如何检测出恶意代码的? 基于特征码的检测(杀软的特征库中包含了一些数据或者数据段,杀软会尽可能的更新这个特征库,以包括尽可能多的恶意代 ...
- Asp.Net StateServer实现共同域名下Session共享
概述 在实验的时候,参照了多方的信息,确实成功了,这里简单记录一下. 我们知道,在Asp.Net的Web.Config文件中,System.Web节点下,有个sessionState节点,它说明了应用 ...
- Node.js 下载路径/微软产品下载路径
https://nodejs.org/en/ https://www.microsoft.com/en-us/download //微软官方下载地址,可以下载VS2015 SQL 等 微软产品
- Hexo站点之域名配置【2】
该系列博客列表请访问:http://www.cnblogs.com/penglei-it/category/934299.html 摘要 因为Hexo个人博客是托管在github之上,每次访问都要使用 ...
- Linux下tomcat的启动,关闭,以及shutdown失败杀死进程的方法
1.tomcat服务器第一次启动并查看启动日志的命令 在 ../bin 文件夹下输入./startup.sh;tail -f ../logs/catalina.out 2.需要重启服务器的时候 在 . ...
- B1022. D进制的A+B
除基取余法 #include<bits/stdc++.h> using namespace std; stack<int> s; int main(){ long long a ...