UVALive 6439 -- Pasti Pas!

Source: Internet
Author: User

UVALive 6439 -- Pasti Pas!

This is because it requires the longest text string. On the one hand, we walk forward from the past, on the other hand, when we get the same part for a whole, in this way, we can get the longest input string. then the problem is that if we judge whether the strings in the first and second parts of the enumeration are the same, we can also determine the brute force code, but this will definitely return timeout, so we use the string hash method to judge.

The Code is as follows:

#include
  
   #include
   
    #include
    
     using namespace std;typedef  unsigned long long ull;ull Hash[50500];char str[50500];int main(){      //freopen("in.txt","r",stdin);      Hash[0]=1;      for(int i=1;i<=50500;i++)           Hash[i]=Hash[i-1]*31;      int t,Case=0;      scanf("%d",&t);      while(t--)      {            scanf("%s",str);            int l=0,r=strlen(str)-1;            int ans=0,len=0;            ull x=0,y=0;            while(1)            {                  if(l==r)                  {                      ans++; break;                  }                  if(l>r)                  {                      if(x||y)                           ans++;                     break;                  }                  if(x==0&&y==0&&str[l]==str[r])                  {                        ans+=2;                        l++;r--; len=0;                        continue;                  }                  x=x*31+(str[l]-'A');                  y+=Hash[len]*(str[r]-'A');                  len++;                  if(x==y)                  {                       ans+=2;                       x=0,y=0,len=0;                  }                  l++; r--;            }            printf("Case #%d: %d\n",++Case,ans);      }   return 0;}
    
   
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.