CF-Round#403 Div2 A. Andryusha and Socks
2017-03-10 20:59
260 查看
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
output
input
output
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.
思路:
若输入的袜子 在桌子上没有另一只,则放在桌子上,number+1;若桌子上存在另一只,则把这一双袜子放在衣柜里,number-1
代码如下:
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.
思路:
若输入的袜子 在桌子上没有另一只,则放在桌子上,number+1;若桌子上存在另一只,则把这一双袜子放在衣柜里,number-1
代码如下:
#include<stdio.h>
#include<string.h>
#define maxn 100000+2int a[maxn];
int main()
{
memset(a, 0, sizeof(a));
int n;
while (scanf("%d", &n) != EOF)
{
int t = 2 * n;
int num = 0, maxnum = 0;
while (t--)
{
int x;
scanf("%d", &x);
if (a[x] == 0)
{
a[x]++;
num++;
if (num > maxnum)maxnum = num;
}
else
{
a[x]--;
num--;
}
}
printf("%d\n",maxnum);
}
return 0;
}
相关文章推荐
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks
- Codeforces Round #403 (Div. 2) A. Andryusha and Socks(简单模拟)
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
- CF-Round#403 Div2 B. The Meeting Place Cannot Be Changed
- CodeForces 780A Andryusha and Socks【水题】
- 【CF】259 Div.1 B Little Pony and Harmony Chest
- 【CF】121 Div.1 C. Fools and Roads
- CF-Codeforces Round #410 (Div. 2)-D-Mike and distribution
- Codeforces Round #262 (Div. 2) A. Vasya and Socks
- CF Round #348 Div. 2 A. Little Artem and Present B. Little Artem and Grasshopper C. Little Artem and
- cf 372 div2 E. Sonya and Problem Wihtout a Legend dp
- 【codeforces 782A】Andryusha and Socks
- Andryusha and Socks vj
- CF(#294 div2):D. A and B and Interesting Substrings
- 【codeforce】403 Div.2 A Andryusha and Socks
- CF 299 div2 D. Tavas and Malekas(KMP)
- CF Codeforces Round #257 (Div. 1) A (449A) Jzzhu and Chocolate
- CF 280B. Vanya and Lanterns(div2)
- Codeforces #262 (Div. 2) A. Vasya and Socks(水题)
- CF(#293 div2):A:Vitaly and Strings