hdu2369 Broken Keyboard(类似dfs)
转载请注明出处:http://blog.csdn.net/u012860063
题目链接: pid=2369">http://acm.hdu.edu.cn/showproblem.php? pid=2369
代码例如以下:
#include <cstdio>
#include <cstring>
char s[1100047];
int hash[247];
int main()
{
__int64 n;
while(~scanf("%I64d",&n) && n)
{
getchar();
gets(s);
__int64 len = strlen(s);
memset(hash,0,sizeof(hash));
__int64 i, star = 0, ans = 0, diff = 0;
for(i = 0; i < len; i++)
{
++hash[s[i]];//映射值+1
if(hash[s[i]] == 1)//假设是第一次出现
{
diff++;//不同字母数+1
if(diff > n)//假设超过n个不同字母
{
while(--hash[s[star++]] > 0);//起点向右挪动 直到消去一个字母
diff--;//不同字母数返回正常取值
}
}
int LEN = i-star+1;//获得这个字符串长度
ans = ans > LEN?ans:LEN;//保存最大
}
printf("%I64d\n",ans);
}
return 0;
}
hdu2369 Broken Keyboard(类似dfs)的更多相关文章
- N - Broken Keyboard (a.k.a. Beiju Text)(DFS,链表)
N - Broken Keyboard (a.k.a. Beiju Text) Time Limit:1000MS Memory Limit:0KB 64bit IO Format:% ...
- UVa 11998 Broken Keyboard (数组模拟链表问题)
题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int m ...
- UVa 11988 Broken Keyboard(链表->数组实现)
/*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end ...
- 1084. Broken Keyboard (20)
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...
- B - Broken Keyboard (a.k.a. Beiju Text)
Problem B Broken Keyboard (a.k.a. Beiju Text) You're typing a long text with a broken keyboard. Well ...
- uva - Broken Keyboard (a.k.a. Beiju Text)(链表)
11988 - Broken Keyboard (a.k.a. Beiju Text) You’re typing a long text with a broken keyboard. Well i ...
- PAT1084:Broken Keyboard
1084. Broken Keyboard (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue On a ...
- PAT 1084 Broken Keyboard
1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type ...
- A1084. Broken Keyboard
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...
随机推荐
- char与unsigned char 差别
char 与 unsigned char的本质差别 http://bbs.csdn.net/topics/270080484 同一个内存内容:10010000 你用char* 解释是-1 ...
- Agile/CMMI/Scrum
Agile/CMMI/Scrum 一.背景介绍 在朋友(aehyok)的建议下,初步去了解Visual Studio Online,简称VS Online(即原来的 Team Foundation S ...
- 乐在其中设计模式(C#) - 装饰模式(Decorator Pattern)
原文:乐在其中设计模式(C#) - 装饰模式(Decorator Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 装饰模式(Decorator Pattern) 作者:weba ...
- linux基础知识1
1. 硬盘分区 分区类型:主分区,扩展分区.逻辑分区: 分区规则: 一个硬盘仅仅能有1到4个主分区: 一个硬盘仅仅能有1个扩展分区: 一个硬盘的主分区和扩展分区最多仅仅能有4个. 扩展分区仅仅能用来包 ...
- [LeetCode145]Binary Tree Postorder Traversal
题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...
- [LeetCode116]Path Sum
题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...
- ASP.NET5
ASP.NET5 2015年11月30日, ASP.NET 5 RC1 已经发布,本文尝试了一下ASP.NET5项目的创见一发布到IIS.开发环境,win10 64位,visual studio201 ...
- 图表引擎AChartEngine 一
MainActivity.java package com.example.achartengine0; import org.achartengine.ChartFactory; import or ...
- 开源Math.NET基础数学类库使用(07)一些常用的数学物理常数
原文:[原创]开源Math.NET基础数学类库使用(07)一些常用的数学物理常数 本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/ ...
- NYOJ 14 场地安排
/* 中国标题的含义: 中国的翻译: 标题效果:寻求预定场地的最大数量,只有一个活动可以安排时间 解决问题的思路:然后使用结构数.之后再构建一个排序,排序结束时间活动.然后基于开始时间为大于一个事件的 ...