zoukankan      html  css  js  c++  java
  • L

    Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a machine that captures snowflakes as they fall, and serializes them into a stream of snowflakes that flow, one by one, into a package. Once the package is full, it is closed and shipped to be sold.

    ne by one, into a package. Once the package is full, it is closed and shipped to be sold. The marketing motto for the company is “bags of uniqueness.” To live up to the motto, every snowflake in a package must be different from the others. Unfortunately, this is easier said than done, because in reality, many of the snowflakes flowing through the machine are identical. Emily would like to know the size of the largest possible package of unique snowflakes that can be created. The machine can start filling the package at any time, but once it starts, all snowflakes flowing from the machine must go into the package until the package is completed and sealed. The package can be completed and sealed before all of the snowflakes have flowed out of the machine.

    Input

    The first line of input contains one integer specifying the number of test cases to follow. Each test case begins with a line containing an integer n, the number of snowflakes processed by the machine. The following n lines each contain an integer (in the range 0 to 109 , inclusive) uniquely identifying a snowflake. Two snowflakes are identified by the same integer if and only if they are identical. The input will contain no more than one million total snowflakes.

    Output

    For each test case output a line containing single integer, the maximum number of unique snowflakes that can be in a package.

    Sample Input

    1

    5

    1

    2

    3

    Sample Output

    3

    这道题我用的是set  ,注意的是set里的元素是自动排序的,删除要按照输入的顺序删除(这一点是百度了别人的才知道的 - -)。

     1 #include <iostream>
     2 using namespace std;
     3 #include<string.h>
     4 #include<set>
     5 #include<stdio.h>
     6 #include<math.h>
     7 #include<queue>
     8 #include<map>
     9 #include<algorithm>
    10 #include<cstdio>
    11 #include<cmath>
    12 #include<cstring>
    13 #include <cstdio>
    14 #include <cstdlib>
    15 #include<vector>
    16 set<int>TM;
    17 set<int,int>::iterator it;
    18 set<int,int>::iterator ta;
    19 int a[1000011];
    20 int n;
    21 int max1;
    22 void dadiaomengmei()
    23 {
    24      int tou=0,wei=0;
    25     while(wei<n)
    26     {
    27         while(wei<n&&TM.count(a[wei])==0)
    28         {
    29             TM.insert(a[wei++]);
    30             int goubi=TM.size();
    31             max1=max(max1,goubi);
    32         }
    33             TM.erase(a[tou++]);
    34     }
    35 }
    36 int main()
    37 {
    38 
    39     int t;
    40     cin>>t;
    41     while(t--)
    42     {
    43         cin>>n;
    44         max1=0;
    45         long long goubi;
    46         TM.clear();
    47         for(int i=0;i<n;i++)
    48            cin>> a[i];
    49            dadiaomengmei();
    50         cout<<max1<<endl;
    51     }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    html+php超大视频切片上传
    html+php超大视频分片上传
    html+php超大视频上传前端
    html+php超大视频上传讨论
    html+php超大视频上传分享
    MATLAB的设置视点函数view
    matlab 绘制三维图并标注每个点的坐标
    Spring Boot 五种热部署方式,极速开发就是生产力!
    如何提高服务器的并发处理能力?硬核!
    WEB攻击手段及防御第3篇-CSRF
  • 原文地址:https://www.cnblogs.com/dulute/p/7274223.html
Copyright © 2011-2022 走看看