CF782A Andryusha and Socks
题意:
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?
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.
Print single integer — the maximum number of socks that were on the table at the same time.
1
1 1
1
3
2 1 1 3 2 3
2
思路:
水题不解释。
实现:
#include <cstdio>
#include <iostream>
using namespace std;
int cnt[], tmp, n;
int main()
{
cin >> n;
int all = ;
int maxn = -;
for (int i = ; i < * n; i++)
{
cin >> tmp;
cnt[tmp]++;
if (cnt[tmp] == )
all--;
else
all++;
if (maxn < all)
maxn = all;
}
cout << maxn << endl;
return ;
}
最新文章
- python datetime处理时间
- mysql学习(二)
- IE和FF区别关于css和js
- js获取项目根路径
- 深入.NET平台和C#编程 错题录
- 动态更换view类的背景---StateListDrawable的应用
- C# 通过ImportNode AppendChild方法合并XmlDocument,XML转为DataTable
- ckplayer
- Jersey实现Restful服务
- Flux和ExtJS MVC框架的异同点介绍
- ANIS与UNICODE字符格式转换:MultiByteToWideChar() 和WideCharToMultiByte() 函数
- 步步为营-90-SEO(url重写+超链接技巧)
- python3 小工具
- 设计模式:装饰模式(decorate)
- 汇编 SETG,SETL ,SETGE, SETLE指令
- SQL Server - 开窗函数
- mysql join left join区别
- 7.翻译:EF基础系列---EF中的实体类型
- numpy和matplotlib绘制直方图
- typecho去index.php