zoukankan      html  css  js  c++  java
  • UVA

    题目:点击打开题目链接

    思路:从左往右扫描,定义扫描左端点L,右端点R,保证每次往几何中添加的都是符合要求的连续的数列中的元素,L和R从0扫到n,复杂度为O(n),使用set维护子数列,set查找删除都是O(logn),所以复杂度为O(nlogn),应特别注意set内并不是原子数列顺序,若要删除子数列起始元素,不能使用begin迭代器

    AC代码:

     1 #include <iostream>
     2 #include <set>
     3 #include <algorithm>
     4 #include <cstdio>
     5 
     6 using namespace std;
     7 
     8 const int maxn = 1000000 + 5;
     9 int num[maxn];
    10 
    11 int main()
    12 {
    13     //freopen("1.txt", "r", stdin);
    14     int T; cin >> T;
    15     while(T--) {
    16         int n; cin >> n;
    17         for(int i = 0; i < n; i++)
    18             cin >> num[i];
    19 
    20         set<int> temp;
    21         int L = 0, R = 0, ans = 0;
    22 
    23         while(R < n) {
    24             while(R < n && temp.find(num[R]) == temp.end())
    25                 temp.insert(num[R++]);
    26             ans = max(ans, (int)temp.size());
    27             temp.erase(num[L++]);
    28         }
    29         cout << ans << endl;
    30     }
    31     return 0;
    32 }
    版权声明:该博客版权归本人所有,若有意转载,请与本人联系
  • 相关阅读:
    渣渣的python的上路
    【tyvj 2038】诡异的数学题
    codeforces_733_A
    NOIP2011 选择客栈
    NOIP 2012 同余方程
    灵渊(seals.cpp/c/pas)
    NOIP 2012 开车旅行
    Mybatis初步详细配置
    SpringMVC之编程式校验
    Spring整合MyBaytis
  • 原文地址:https://www.cnblogs.com/fan-jiaming/p/9440201.html
Copyright © 2011-2022 走看看