Daydream(2668)

Daydream

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1159 Accepted Submission(s): 326


Problem Description
Welcome to 2009 HDU Girl’s Cup, bless you will happy in it.
Every girl 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.
Daydream(2668)
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.

Input
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
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.

Sample Input
3 abc 5 aaaba 8 hdugirls

Sample Output
3 0 2
2 2 3
8 0 7
AC代码
    • #include<iostream>
  1. #include<cmath>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<map>
  5. using namespace std;
  6. char s[10000009];
  7. char m[176];
  8. int main()
  9. {
  10. int n;
  11. while(scanf("%d",&n)!=EOF)
  12. {
  13. scanf("%s",s);
  14. int len=strlen(s);
  15. int ss=0,ee=0;
  16. int ans=0,anss,anse;
  17. memset(m,0,sizeof(m));
  18. for(int i=0;i<len;i++)
  19. {
  20. ee=i;
  21. if(m[s[i]]==0)
  22. {
  23. m[s[i]]=1;
  24. if(ee-ss+1>ans)//一旦有长度大于原先记录的最大长度,就替换
  25. {
  26. ans=ee-ss+1;
  27. anss=ss;
  28. anse=ee;
  29. }
  30. }
  31. else
  32. {
  33. for(int j=ss;j<=ee;j++)//找到重复字母的位置,把扫描起点移到它的后一个字母
  34. if(s[j]==s[i]){ss=j+1;break;}
  35. else m[s[j]]=0;//把目前扫描起点和出现重复点之间出现字母的标记清空
  36. }
  37. }
  38. printf("%d %d %d\n",ans,anss,anse);
  39. }
  40. return 0;
  41. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值