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 }
  • 相关阅读:
    导出报ora-31634、ora-31664
    A significant part of sql server process memory has been paged out
    解决ora-02429:无法用于删除强制唯一/主键的索引
    更改数据库表中有数据的字段类型NUMERIC(18,2)为NUMERIC(18,6)
    GHOST CLEANUP Process
    oracle查看执行计划explain plan FOR
    ORA-01502: 索引或这类索引的分区处于不可用状态
    mysql 游标循环,嵌套游标循环
    MSSQL FOR XML PATH ('')用法
    Mysql CHARINDEX用法
  • 原文地址:https://www.cnblogs.com/wangyiming/p/6516523.html
Copyright © 2011-2022 走看看