HDU 2668 Daydream
用一个队列来维护
每次加入一个字符,如果字符没有在队列里,那么直接入队,并且检查更新队列大小。
如果加入的字符在队列里了,那么要一直弹出队首,直到弹出的字符和当前要插入的一样。
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<iostream>
- #include<queue>
- #include<algorithm>
- using namespace std;
- const int maxn=+;
- queue<int>Q;
- char s[maxn];
- int flag[];
- int ans1,ans2,ans3;
- int n;
- int main()
- {
- while(~scanf("%d",&n))
- {
- memset(flag,,sizeof flag);
- while(!Q.empty()) Q.pop();
- scanf("%s",s);
- ans1=-;
- for(int i=; i<n; i++)
- {
- if(flag[s[i]]==)
- {
- flag[s[i]]=;
- Q.push(i);
- if(i-Q.front()+>ans1)
- {
- ans1=i-Q.front()+;
- ans2=Q.front();
- ans3=i;
- }
- }
- else if(flag[s[i]]==)
- {
- while()
- {
- int h=Q.front();
- Q.pop();
- flag[s[h]]=;
- if(s[h]==s[i]) break;
- }
- Q.push(i);
- flag[s[i]]=;
- }
- }
- printf("%d %d %d\n",ans1,ans2,ans3);
- }
- return ;
- }
HDU 2668 Daydream的更多相关文章
- hdu_2668 Daydream O(n)求最长不重复子串
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2668 Daydream Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 2669 Romantic (乘法逆元)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 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 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDU 2669 Romantic(裸的拓展欧几里得)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- Swift-HELP
//获取网页地址对应的字符串 var urlString = url.absoluteURL.absoluteString
- CURL访问url显示响应时间
curl -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} http://www.baidu.com 时间指 ...
- 注册表被篡改,请重新安装应用程序 acdphotoEdit
破解之后,运行程序,提示“注册表被篡改,请重新安装应用程序”,反复重装,重启,都不行,删除注册表,重新安装后运行一次ACDSee,绿化,也不行,最后发现设置属性以管理员权限运行,ok,解决了
- 进入BIOS SHELL DUMP 命令
LINUX系统 进入SHELL 输入命令 fs1: or fs0: 就进入了U盘目录 然后输入 ACPIRW.efi -d -s dsdt.bat 就会产生结果到U盘 ——————————————— ...
- linker command failed with exit code 1 (use -v to see
转自 :http://www.reader8.cn/jiaocheng/20131022/2003334.html Undefined symbols for architecture http:// ...
- ssh连接ubuntu提示连接不上的问题
今天在自己的电脑上安装了最新版本的 ubuntu (我都在root用户下运行,非root用户请添加sudo命令) uname -rvo 运行结果为 3.13.0-32-generic #57-Ubun ...
- 设计模式--静态工厂设计模式在android中的使用
今天看到这篇文章:http://www.androiddesignpatterns.com/2012/05/using-newinstance-to-instantiate.html public c ...
- Chapter 2 Open Book——13
"People in this town," he muttered. "Dr. Cullen is a brilliant surgeon who could prob ...
- 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 ...
- 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 ...