Daydream
2013-12-07 20:22
253 查看
描述
Welcome to 2009 HDU Girl’s Cup, bless you will happy in it.
Every girls are beautiful if you use you heart to feel. Every corner in the world will colourful and energetic by several girls standing. If you boy, a normal bay, I believe that you will try to watch when a beautiful girl passing you and you will nervous if
a girl watching you just when you are watching her.
Now give you a surprise that may be never happy in the real time. Millions of PLMM stand in a line and facing you(^_^). They are dress colourful clothings. You should to find out a maximal subline PLMM that their clothing color are all different.
输入
The input contains multiple test cases.
Each case first give a integer n expressing many many girls stand in line.(n<=10000000)
Next line a string including n character, each character standing one girls’s clothing color.
输出
Output one integer the numbers of maximal subline PLMM that their clothing color are all different and the line's begin and end (based from 0). If their are more answer, print the begin
smallest.
样例输入
3
abc
5
aaaba
8
hdugirls
样例输出
3 0 2
2 2 3
8 0 7
和吉首大学热身赛的题目,当时题意没看懂,现在知道了,就是求最长不重复子序列,输出他的长度、初始及结束位置
Welcome to 2009 HDU Girl’s Cup, bless you will happy in it.
Every girls are beautiful if you use you heart to feel. Every corner in the world will colourful and energetic by several girls standing. If you boy, a normal bay, I believe that you will try to watch when a beautiful girl passing you and you will nervous if
a girl watching you just when you are watching her.
Now give you a surprise that may be never happy in the real time. Millions of PLMM stand in a line and facing you(^_^). They are dress colourful clothings. You should to find out a maximal subline PLMM that their clothing color are all different.
输入
The input contains multiple test cases.
Each case first give a integer n expressing many many girls stand in line.(n<=10000000)
Next line a string including n character, each character standing one girls’s clothing color.
输出
Output one integer the numbers of maximal subline PLMM that their clothing color are all different and the line's begin and end (based from 0). If their are more answer, print the begin
smallest.
样例输入
3
abc
5
aaaba
8
hdugirls
样例输出
3 0 2
2 2 3
8 0 7
和吉首大学热身赛的题目,当时题意没看懂,现在知道了,就是求最长不重复子序列,输出他的长度、初始及结束位置
#include<iostream> #include<cstring> #include<cstdio> using namespace std; char str[10000005]; int main() { int a[300],i; int n,mx,mi,x,s; while(~scanf("%d",&n)) { scanf("%s",str); memset(a,0,sizeof(a)); mx=mi=x=s=i=0; a[str[i]]=1; while(str[i]){ i++; if(a[str[i]]==0) a[str[i]]=1; else { x=i-1; if(x-s>mx-mi){ mx=x; mi=s; } for(int j=s;j<=x;j++){ if(str[j]==str[i]){ s = j+1; break; } else a[str[j]]=0; } } if(i-1-s>mx-mi) { mx=i-1; mi=s; } } printf("%d %d %d\n",mx-mi+1,mi,mx); } return 0; }
相关文章推荐
- 2.Configuration、SessionFactory、Session的关系与持久化对象的状态
- JAVA变量初始化顺序
- 获取字符串
- 最小生成树——Kruskal
- 线性代数
- 使用Unity创建依赖注入
- Codeforces Round #217 (Div. 2)
- 如何将json字符串转化成json对象呢
- oc中的类学习笔记1
- Java Hour 59 JVM Heap
- Copy List with Random Pointer
- 如果当初学习编程时能有人给我这些忠告该多好
- Oracle诊断案例-Sql_trace之二
- Dreamweaver CS6破解教程[序列号+破解补丁]
- Java Spring Tutorial -- Singleton and Prototype Bean Scopes
- stl pair 应用
- Objective-C编程(第3版)
- 等你,不是一生。炊烟起了,我在门口等你
- Java策略模式(Strategy)
- 链表