Conclusion Jzoj 5912 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 hint This question is really interesting.

Analysis

First we know that the optimal strategy is to do the opposite with each other (obviously)

And then we'll start by talking about string one minus the number of characters with even numbers left.

First, if there's a string in the middle, Pty must win.

Then we consider the case where the string is shifted left and right.

Pty can be deleted on the other side after the deletion of the other side, and the other side in order to win will reverse the operation, then you can go to the left/right more than one lattice, but also only one more

Then there are only two of the even cases:

1, right in the middle

2, the middle of the offset of a lattice are two series

Consider an odd number, easy to think about and even the same situation (2)

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;stringb;intMain () {Freopen ("vanusee.in","R", stdin); Freopen ("Vanusee.out","W", stdout); intT; scanf ("%d",&t);  while(t--) {cin>>a>>b; intL1=a.length (), l2=b.length (); if(l1<=L2) {            if(a==b) {printf ("pty\n"); Continue; } printf ("cqf\n"); Continue; }        if(! ((L1-L2)%2)) {            stringAleft=a.substr ((l1-l2>>1)-1, L2), amid=a.substr ((l1-l2>>1), L2), aright=a.substr ((l1-l2>>1)+1, L2); if(aleft==aright&&aleft==b| | amid==b) {printf ("pty\n"); Continue; } printf ("cqf\n"); Continue; }        stringAleft=a.substr (l1-l2>>1, L2), aright=a.substr ((l1-l2>>1)+1, L2); if(aleft==aright&&aleft==b) printf ("pty\n"); Elseprintf"cqf\n"); }}
View Code

Conclusion Jzoj 5912 Vanusee

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.