博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AC日记——Andryusha and Socks Codeforces 780a
阅读量:6823 次
发布时间:2019-06-26

本文共 3081 字,大约阅读时间需要 10 分钟。

A. Andryusha and Socks
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Andryusha is an orderly boy and likes to keep things in their place.

Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.

Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?

Input

The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs.

The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi.

It is guaranteed that Andryusha took exactly two socks of each pair.

Output

Print single integer — the maximum number of socks that were on the table at the same time.

Examples
input
1 1 1
output
1
input
3 2 1 1 3 2 3
output
2
Note

In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.

In the second example Andryusha behaved as follows:

  • Initially the table was empty, he took out a sock from pair 2 and put it on the table.
  • Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table.
  • Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe.
  • Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table.
  • Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe.
  • Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
Thus, at most two socks were on the table at the same time.
 
思路:
  模拟;
 
 
来,上代码:
#include 
#include
#define maxn 100005using namespace std;int n,pos,ans,pos_;char Cget;bool if_[maxn];inline void in(int &now){ now=0,Cget=getchar(); while(Cget>'9'||Cget<'0') Cget=getchar(); while(Cget>='0'&&Cget<='9') { now=now*10+Cget-'0'; Cget=getchar(); }}int main(){ in(n); for(int i=1;i<=(n<<1);i++) { in(pos_); if(!if_[pos_]) { if_[pos_]=true; pos++; ans=max(ans,pos); } else pos--; } cout<

 

转载于:https://www.cnblogs.com/IUUUUUUUskyyy/p/6556194.html

你可能感兴趣的文章
java自学篇之程序设计基础
查看>>
swiper的基础使用(五)
查看>>
Windows Server 2012R2 Hyper-v之虚拟机复制(2)
查看>>
大数据各种实用网站
查看>>
win7安装laravel
查看>>
Oracle 各后台进程功能说明
查看>>
屏蔽storm ui的kill功能
查看>>
我的友情链接
查看>>
Oracle Decode函数的使用
查看>>
MSF学习笔记
查看>>
经典脚本案例--check memory
查看>>
20.31 expect脚本同步文件;20.32 expect脚本指定host和要同步的文件;20.33 构建文件分发系统;20.34...
查看>>
CentOS单用户与救援模式
查看>>
postfix 源码centos7上搭建及错误提示---亲测
查看>>
【Redis篇】Redis集群安装与初始
查看>>
jquery基础
查看>>
C# 集合已修改;可能无法执行枚举操作
查看>>
FSM Code Generator
查看>>
JDBC学习笔记——事务、存储过程以及批量处理
查看>>
JVM内存结构
查看>>