• 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?

    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

    思路:

    水题不解释。

    实现:

     1 #include <cstdio>
     2 #include <iostream>
     3 using namespace std;
     4 int cnt[100005], tmp, n;
     5 int main()
     6 {
     7     cin >> n;
     8     int all = 0;
     9     int maxn = -1;
    10     for (int i = 0; i < 2 * n; i++)
    11     {
    12         cin >> tmp;
    13         cnt[tmp]++;
    14         if (cnt[tmp] == 2)
    15             all--;
    16         else
    17             all++;
    18         if (maxn < all)
    19             maxn = all;
    20     }
    21     cout << maxn << endl;
    22     return 0;
    23 }
  • 相关阅读:
    工作总结 vue 城会玩
    vue中,class、内联style绑定、computed属性
    vue-router2.0 组件之间传参及获取动态参数
    vue-router(2.0)
    在v-for中利用index来对第一项添加class(vue2.0)
    机器学习:从入门到沉迷
    探索AutoLayout的本质和解决一些问题
    软件的极简主义
    数组最大差值的最优解法(动态规划)
    项目管理--敏捷开发在项目中使用
  • 原文地址:https://www.cnblogs.com/wangyiming/p/6516523.html
Copyright © 2020-2023  润新知