ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

hdu 5030 Rabbit's String(ºó׺Êý×é&¶þ·Ö)
2015-07-20 17:34:50 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:1´Î
Tags£ºhdu 5030 Rabbit' String ºó׺ & ;¶þ·Ö

Rabbit's String

Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 288 Accepted Submission(s): 108


Problem Description Long long ago, there lived a lot of rabbits in the forest. One day, the king of the rabbit kingdom got a mysterious string and he wanted to study this string.

At first, he would divide this string into no more than k substrings. Then for each substring S, he looked at all substrings of S, and selected the one which has the largest dictionary order. Among those substrings selected in the second round, the king then choose one which has the largest dictionary order, and name it as a "magic string".

Now he wanted to figure out how to divide the string so that the dictionary order of that "magic string" is as small as possible.
Input There are at most 36 test cases.

For each test case, the first line contains a integer k indicating the maximum number of substrings the king could divide, and the second line is the original mysterious string which consisted of only lower letters.

The length of the mysterious string is between 1 and 10 5 and k is between 1 and the length of the mysterious string, inclusive.

The input ends by k = 0.
Output For each test case, output the magic string.
Sample Input
3
bbaa
2
ababa
0

Sample Output
b
ba

Hint   For the first test case, the king may divide the string into "b", "b" and "aa".
   For the second test case, the king may divide the string into "aba" and "ba". 

Source 2014 ACM/ICPC Asia Regional Guangzhou Online
Recommend hujie | We have carefully selected several similar problems for you: 5053 5052 5051 5050 5049 ÌâÒ⣺ ¸øÄãÒ»¸ö³¤¶È²»³¬¹ý1e5µÄ´®¡£Äã×î¶à¿ÉÒÔ°ÑËüÇгÉk¸öÁ¬ÐøµÄ×Ó´®¡£È»ºó¶ÔÓÚÇгöÀ´µÄ×Ó´®ÄóöËûÃÇ×Ó´®×ÖµäÐò×î´óµÄÄǸö(×Ó´®µÄ×Ó´®)¡£È»ºó°ÑËùÓÐÄóöÀ´µÄ×Ó´®µÄ×Ó´®×ÖµäÐò×î´óµÄÄǸö´®½Ðħ·¨´®¡£ÏÖÔÚÒªÄãÊä³ö×ÖµäÐò×îСµÄħ·¨´®¡£ ˼·£º ×î´óÖеÄ×îС¡£ºÜÈÝÒ×Ïëµ½¶þ·Ö(ÏÖÔÚ¶¼ÊÇÌõ¼þ·´ÉäÁË)¡£Ê×ÏÈÎÒÃÇÇó³ösa,height¡£È»ºó¾Í¿ÉÒÔÇó³öf[i]¼´ÅÅÃûǰiµÄºó׺ÖÐÓжàÉÙ¸ö²»Í¬µÄ×Ó´®¡£È»ºóÎÒÃǶþ·Öħ·¨´®µÄÅÅÃû¡£Í¨¹ýÅÅÃûÎÒÃÇ¿ÉÒÔ½èÖúfÊý×鶨λħ·¨´®ËùÊôºó׺µÄÅÅÃûposºÍħ·¨´®µÄ³¤¶Èlen¡£ÏÖÔÚÒª½â¾öµÄÊÇÔõôÅжϷ½°¸ÊÇ·ñ¿ÉÐÐÁË¡£¶ÔÓÚÅÅÃû´óÓÚposµÄºó׺xÈç¹ûtp=lcp(pos,x)=0¿Ï¶¨Î޽⡣²»¹ÜÔõôÇж¼Ã»Ó᣷ñÔòÎÒÃÇ¿ÉÒÔÔÚ[sa[x],sa[x]+tp-1]Ñ¡¸öλÖÃÇÐÒ»µ¶¡£¶ÔÓÚposºóµÄºó׺¶¼±ê¼ÇÒ»´Î¡£È»ºó̰ÐÄÀ´ÇС£¿´×îÉÙÇжàÉÙµ¶¡£È»ºó¾Í¿ÉÒÔÅж¨ÁË¡£ Ïêϸ¼û´úÂ룺
#include
  
   
#include
   
     #include
    
      #include
     
       using namespace std; const int INF=0x3f3f3f3f; const int maxn=100010; typedef long long ll; char txt[maxn]; int sa[maxn],T1[maxn],T2[maxn],ct[maxn],he[maxn],rk[maxn],n,m,cut; int mk[maxn]; ll f[maxn],ans; void getsa(char *st) { int i,k,p,*x=T1,*y=T2; for(i=0; i
      
       =0; i--) sa[--ct[x[i]]]=i; for(k=1,p=1; p
       
        =k) y[p++]=sa[i]-k; for(i=0; i
        
         =0; i--) sa[--ct[x[y[i]]]]=y[i]; for(swap(x,y),p=1,x[sa[0]]=0,i=1; i
         
          len)//¿´×Ô¼ºËùÊôºó׺ÊÇ·ñÒªÇÐ mk[sa[pos]]=sa[pos]+len-1; for(i=pos+1;i<=n;i++) { if(he[i]==0) return false; len=min(len,he[i]);//lcp mk[sa[i]]=sa[i]+len-1;//ÅÅÐò±Èpos´óÒ»¶¨Òª·Ö¸î¡£ } pp=n,cnt=0; for(i=0;i
          
           cut) return false; pp=n; } } return cnt
           
            >1; if(isok(mid)) ans=mid,hi=mid-1; else low=mid+1; } pos=lower_bound(f+1,f+1+n,ans)-f; len=he[pos]+ans-f[pos-1]; txt[sa[pos]+len]=0; printf("%s\n",txt+sa[pos]); } return 0; } 
           
          
         
        
       
      
     
    
   
  


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºBZOJ 1507 NOI 2003 Editor Splay ÏÂһƪ£ºhdu 4223 Dynamic Programming? (..

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)