HDU 2369 Broken Keyboard(乱搞)
两个月前写的一个题,怎么搞怎么RE了,算法也知道,今天比赛又做,居然1Y。。。
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #define eps 1e-9 5 char str[5000001]; 6 int o[301]; 7 int main() 8 { 9 int i,j,n,st,len,max,num; 10 while(scanf("%d%*c",&n)!=EOF) 11 { 12 memset(o,0,sizeof(o)); 13 if(!n) break; 14 gets(str); 15 len = strlen(str); 16 st = 0; 17 max = 0; 18 num = 0; 19 for(i = 0;i <= len-1;i ++) 20 { 21 j = str[i]; 22 if(!o[j]) 23 { 24 num ++; 25 } 26 o[j] ++; 27 if(num > n) 28 { 29 for(;;) 30 { 31 if(num == n) 32 break; 33 j = str[st]; 34 if(o[j] == 1) 35 num --; 36 st ++; 37 o[j] --; 38 } 39 } 40 if(max < i-st+1) 41 max = i-st+1; 42 } 43 printf("%d\n",max); 44 } 45 return 0; 46 }