用一个队列来维护

每次加入一个字符,如果字符没有在队列里,那么直接入队,并且检查更新队列大小。

如果加入的字符在队列里了,那么要一直弹出队首,直到弹出的字符和当前要插入的一样。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<queue>
  6. #include<algorithm>
  7. using namespace std;
  8.  
  9. const int maxn=+;
  10. queue<int>Q;
  11. char s[maxn];
  12. int flag[];
  13. int ans1,ans2,ans3;
  14. int n;
  15.  
  16. int main()
  17. {
  18. while(~scanf("%d",&n))
  19. {
  20. memset(flag,,sizeof flag);
  21. while(!Q.empty()) Q.pop();
  22. scanf("%s",s);
  23. ans1=-;
  24.  
  25. for(int i=; i<n; i++)
  26. {
  27. if(flag[s[i]]==)
  28. {
  29. flag[s[i]]=;
  30. Q.push(i);
  31. if(i-Q.front()+>ans1)
  32. {
  33. ans1=i-Q.front()+;
  34. ans2=Q.front();
  35. ans3=i;
  36. }
  37. }
  38. else if(flag[s[i]]==)
  39. {
  40. while()
  41. {
  42. int h=Q.front();
  43. Q.pop();
  44. flag[s[h]]=;
  45. if(s[h]==s[i]) break;
  46. }
  47. Q.push(i);
  48. flag[s[i]]=;
  49. }
  50. }
  51.  
  52. printf("%d %d %d\n",ans1,ans2,ans3);
  53. }
  54. return ;
  55. }

HDU 2668 Daydream的更多相关文章

  1. hdu_2668 Daydream O(n)求最长不重复子串

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2668 Daydream Time Limit: 2000/1000 MS (Java/Others)  ...

  2. hdu 2669 Romantic (乘法逆元)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  4. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  5. HDU 2669 Romantic(裸的拓展欧几里得)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  6. HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)

    Rank of Tetris Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. Swift-HELP

    //获取网页地址对应的字符串 var urlString = url.absoluteURL.absoluteString

  2. CURL访问url显示响应时间

    curl -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} http://www.baidu.com 时间指 ...

  3. 注册表被篡改,请重新安装应用程序 acdphotoEdit

    破解之后,运行程序,提示“注册表被篡改,请重新安装应用程序”,反复重装,重启,都不行,删除注册表,重新安装后运行一次ACDSee,绿化,也不行,最后发现设置属性以管理员权限运行,ok,解决了

  4. 进入BIOS SHELL DUMP 命令

    LINUX系统 进入SHELL 输入命令 fs1: or fs0: 就进入了U盘目录 然后输入 ACPIRW.efi  -d -s dsdt.bat 就会产生结果到U盘 ——————————————— ...

  5. linker command failed with exit code 1 (use -v to see

    转自 :http://www.reader8.cn/jiaocheng/20131022/2003334.html Undefined symbols for architecture http:// ...

  6. ssh连接ubuntu提示连接不上的问题

    今天在自己的电脑上安装了最新版本的 ubuntu (我都在root用户下运行,非root用户请添加sudo命令) uname -rvo 运行结果为 3.13.0-32-generic #57-Ubun ...

  7. 设计模式--静态工厂设计模式在android中的使用

    今天看到这篇文章:http://www.androiddesignpatterns.com/2012/05/using-newinstance-to-instantiate.html public c ...

  8. Chapter 2 Open Book——13

    "People in this town," he muttered. "Dr. Cullen is a brilliant surgeon who could prob ...

  9. data Mining with Weka: Trailer More Data Mining with Weka 用weka 进行数据挖掘 Weka 用weka 进行更多数据挖掘

    https://www.youtube.com/user/WekaMOOC 大学公开课  视频教程 weka 入门教程 data Mining with Weka: Trailer  More Dat ...

  10. LeetCode OJ 83. Remove Duplicates from Sorted List

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...