Thinking Violence Jzoj P5912 Vanusee

Source: Internet
Author: User

Description as we all know, CQF children's shoes have a deep understanding and understanding of philosophy, and often apply philosophical ideas to real life, such as training wrestling techniques or research (FA).
Because CQF's philosophy of children's shoes is too advanced to affect the Pty, they often give in a vanusee. Van's are some of the best-known usee in the high-end atmosphere such as "equipment recycling free", "opening a kun evolution all by swallowing", "eight o'clock in the evening is brother to liver".
One day they decided to share their philosophical journey with the people of Van Usee.
The rule is this:
"Given two strings s and t,| s| >= | T|.
CQF and Pty take turns to operate the string S,CQF Initiator.
For each operation, CQF or Pty will choose to delete the first or last digit of S.
When the length of the string after the operation equals | T| when the game stops.
If the string =t is stopped, Pty wins, otherwise CQF wins. ”
CQF and Pty have strong philosophical thinking, they can take the best strategy to act.
As a senior player, Mr. Suba in the sidelines, he has already seen through the essence of this usee, when the two string gives the moment of victory and defeat has been divided, but not all onlookers level is like Mr. Suba so high, and there is no grade five points brother, they want to know the results, So the onlookers found you can foresee a game go the next 40 hands of you. Input has multiple sets of data
The first line a positive integer t represents the number of data groups
Next T set of data, two rows per set of data, followed by a total of 2t rows
First line a string s
The second line is a string t
String consists of lowercase characters only Outputt Line, for each group of data output both sides are the best strategy when who is the winner ("CQF" or "Pty", without quotes, lowercase) Sample Input
5ababbabbaaababxyzmnkxyzxyz
Sample Output
Ptyptycqfcqfpty Sample explanation: For the first group of s= "ABA", t= "B" cqf whether to delete or tail, pty can delete the other to make the rest is "B" for the third group s= "Aaab", t= "AB" CQF only the first time to delete "B", You'll never be able to reach "AB" in the future.
data constraint for 30%, 1<=| t|<=| S|<=20
For 100% of data, 1<=t<=10 1<=| t|<=| s|<=100000

Exercises
    • First, when | s|-| When the t| is odd, the CDF is the last operation, so he doesn't want the string to match

    • In this case, if the Pty to win, it can only delete the front character will be able to match, delete the following characters can also match

    • If | s|-| Pty is the last operation when the t| is an even number
    • If 0 is not, and-2 and 2 are not, then CQF will certainly go to the other side, Pty no way to pull it back to that side.

    • So Pty will win when and only if 0 is the target State or-2 and 2 are the target States

    • The string to match in S should be in | s|-| T|/2 started, because if the previous point, CQF has been deleted from the left can also delete the original string
Code
1#include <cstdio>2#include <cstring>3 using namespacestd;4 intN,t,len1,len2,flag;5 Charl1[500010],l2[500010];6 BOOLPdintx)7 {8      for(intI=1; i<=len2;i++)if(L1[x+i]!=l2[i])return false;9     return true;Ten } One intMain () A { -Freopen ("vanusee.in","R", stdin), Freopen ("Vanusee.out","W", stdout); -scanf"%d",&t); the      while(t--) -     { -scanf"%s%s", l1+1, l2+1); -Len1=strlen (l1+1), Len2=strlen (l2+1), flag=0; +         if(len1==len2) -         { +             if(PD (0)) flag=1; A         } at         Else -             if((len1-len2)%2==1) FLAG=PD ((len1-len2-1)/2) &AMP;&AMP;PD ((len1-len2+1)/2); -             ElseFLAG=PD ((LEN1-LEN2)/2)|| PD ((len1-len2-2)/2)|| PD ((len1-len2+2)/2); -         if(flag==1) printf ("pty\n");Elseprintf"cqf\n"); -     }  -}

Thinking Violence Jzoj P5912 Vanusee

Related Article

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.