BNU19990 UVA11572 Unique Snowflakes
来源:互联网 发布:北京市网络挂号平台 编辑:程序博客网 时间:2024/05/17 03:22
Unique Snowflakes
64-bit integer IO format: %lld Java class name: Main
[PDF Link]
Problem A: Unique Snowflakes
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.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 Specification
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 10^9, 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.Sample Input
1512321
Output Specification
For each test case output a line containing single integer, the maximum number of unique snowflakes that can be in a package.Output for Sample Input
3
很经典的题
给一个长度可达一百万的序列 求最长的连续子序列 保证里面没有一个相同的元素
一百万啊 只有可能 O(n) 或者 O(n*logn)了
好像只有后者了
合理使用容器
#include <cstdio>#include <cmath>#include <set>using namespace std;int a[1000005];multiset<int> s;int main(){ int T; scanf("%d", &T); int n, k; while(T--) { s.clear(); scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%d",&a[i]); } if(n==1) {printf("1\n");continue;} if(n==0) {printf("0\n");continue;} s.insert(a[0]); int l = 0, r = 1; int len=1; while(1) { if(s.size()) { if(s.find(a[r])==s.end()) { s.insert(a[r]); int h=s.size(); if(h>len) len=h; r++; if(r == n) break; } else { s.erase(a[l]); l++; } } else { l = r; s.insert(a[r]); r++; if(r == n) break; } } printf("%d\n",len); } return 0;}#include<stdio.h>#include<set>#include<algorithm>using namespace std;const int maxn=1000005;int A[maxn];int main(){ int T,n; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&A[i]); set<int>s; int L=0,R=0,ans=0; while(R<n) { //while(R<n&&s.find(A[R])==s.end()) while(R<n&&!s.count(A[R])) s.insert(A[R++]); ans=max(ans,R-L); s.erase(A[L++]); } printf("%d\n",ans); } return 0;}
- BNU19990 UVA11572 Unique Snowflakes
- Uva11572-Unique Snowflakes
- [UVA11572]Unique Snowflakes[构造]
- UVA11572 Unique Snowflakes(滑窗)
- 解题报告 之 UVA11572 Unique Snowflakes
- UVA11572:Unique Snowflakes(唯一的雪花)
- UVa11572 - Unique Snowflakes(最长的不重复的子数组)
- uva11572 Unique Snowflakes 入门经典II 例题8-7
- Uva11572 Unique Snowflakes【滑动窗口】【例题8-7】
- UVa11572 Unique Snowflakes (贪心+尺取法+set容器)
- Unique Snowflakes
- Unique Snowflakes
- UVA 11572 - Unique Snowflakes
- UVA-11572-Unique snowflakes
- 11572 Unique snowflakes
- uva 11572 unique snowflakes
- UVa 11572 - Unique Snowflakes
- UVa 11572 Unique Snowflakes
- sbt 命令
- C——堆与栈
- 第28节--《深度学习基础介绍-机器学习》课程总结
- Arranging Coins(硬币排列)
- Ubuntu 优麒麟Qt5.7.0安装与快捷方式创建
- BNU19990 UVA11572 Unique Snowflakes
- Codeforce 489E(dp+01分数规划)
- Android产品研发(二十三)-->Android中保存静态秘钥实践
- excel 表合并,超链,重命名
- 我的C/C++库理解之memcpy
- Android产品研发(二十四)-->内存泄露场景与检测
- LDD高级字符驱动程序-poll,epoll,select
- linux中export和source的作用和区别
- Linux 802.11n csi tool的安装注意事项