zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    unix:///tmp/supervisor.sock no such file错误
    学习笔记---java
    linux ps查看
    python-virtualenv(多个独立开发环境)
    windows配置java环境
    学习大牛笔记nginx + gunicorn + supervisor
    python request模块学习
    python requests 和SSL证书
    flask 使用配置证书,证书路径自行修改
    python 安装pip
  • 原文地址:https://www.cnblogs.com/wangyiming/p/6516523.html
Copyright © 2011-2022 走看看