uva 11572 - Unique Snowflakes(和书略有不同)
UVa unique
2023-09-14 09:10:17 时间
本书是关于使用刘汝佳set,
通过收集找到.count()和删除.erase().这种方法比我好。用较短的时间。
我想map这个任务可以完成。但是,这是不容易删除,必须先找到find()标。然后删除索引对应的元素
但map有map的使用方法。以下的方法就是比較easy实现的一种方法。
我本想着这个一边读完就计算出了ans,应该更快一点的。可是其实还不如先读再用set处理来得快。
#include<cstdio> #include<iostream> #include<map> #include<string> #include<algorithm> using namespace std; map<string,int> ma; int main() { int t,n; int ans=0; scanf("%d",&t); while(t--) { ans=0; scanf("%d",&n); ma.clear(); string s1; int L=0,R=0; for(int i=0;i<n;i++) { cin>>s1; if(ma.count(s1)&&ma[s1]>=L) { L=ma[s1]+1; } R++; ans=max(ans,R-L); ma[s1]=i; } printf("%d\n",ans); } return 0; }
版权声明:转载请注明出处凯撒...http://blog.csdn.net/u013382399
相关文章
- Java实现偶数矩阵(Even Parity, UVa 11464)
- 【例题 8-2 UVA-1605】Building for UN
- 【习题 7-3 UVA - 211】The Domino Effect
- 【例题 7-4 UVA - 524】Prime Ring Problem
- 【习题 6-10 UVA - 246】10-20-30
- 【Uva 11080】Place the Guards
- 【Uva 10163】Storage Keepers
- 【UVa 12186】Another Crisis
- UVA - 10162 Last Digit
- UVA 10668 - Expanding Rods(数学+二分)
- uva The Tower of Babylon[LIS][dp]