Unique Snowflakes
来源:互联网 发布:multisim 网络标号 编辑:程序博客网 时间:2024/05/16 17:32
Unique Snowflakes
Description
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 integern, 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
//题意:求最长不重复的序列
思路:用map来记住每个数的位置。map一边存,一边判断,
一旦出现重复数,就把这个重复数前面的全清空。
#include<cstdio>#include<cstring>#include<map>using namespace std;int a[100000010];int main(){int t,i,j,n,count,ans;scanf("%d",&t); while(t--) { scanf("%d",&n); map<int,int>ma; count=ans=0; for(i=1;i<=n;i++) scanf("%d",a+i); for(j=1;j<=n;j++) { if(ma[a[j]]==0) { ma[a[j]]=j;//记住位置 count++; //长度 } else { if(count>ans) ans=count; j=ma[a[j]];//一旦出现重复数a[j],就从j+1位置继续往后走 ma.clear();//清空 count=0; } } if(count>ans) ans=count; printf("%d\n",ans); } return 0;}
0 0
- Unique Snowflakes
- Unique Snowflakes
- UVA 11572 - Unique Snowflakes
- Uva11572-Unique Snowflakes
- UVA-11572-Unique snowflakes
- 11572 Unique snowflakes
- uva 11572 unique snowflakes
- UVa 11572 - Unique Snowflakes
- UVa 11572 Unique Snowflakes
- 11572 - Unique Snowflakes
- 11572 - Unique Snowflakes
- UVA 11572 - Unique Snowflakes
- Uva - 11572 - Unique Snowflakes
- [UVA11572]Unique Snowflakes[构造]
- uva 11572 Unique Snowflakes
- uva 11572 Unique Snowflakes
- HDU 2756 Unique Snowflakes
- uva 11572 Unique Snowflakes
- CUDA和OpenCL异同点比较
- Unity数据库SQL操作
- overridePendingTransition
- Android Studio 快捷键整理分享
- Android给scrollView截图超过屏幕大小形成长图
- Unique Snowflakes
- 第16周OJ-指针(3)
- 聊一聊重构这个磨人的小妖精
- Unity之列的基本操作和约束
- android之截屏(包括截取scrollview与listview的)
- Android Studio绝对实用的新手教程(1)导入第三方包或者运行eclipse项目
- Unity之基础查询,连接数据库
- 指针逆序输出数组
- 第16周OJ-指针(4)