Ultraviolet-12103 Leonardo's notebook

Source: Internet
Author: User


Question: Link


Question: replace B with 26 uppercase letters and ask if there is a replace a, so that a ^ 2 = B

Train of Thought: To sum up a rule: two identical loops with N length are multiplied. When n is an odd number, the result is also a loop with N length; when N is an even number, it is split into two cycles with a length of n/2, therefore, for an odd number of cycles with a length of N, we can find a loop with a length of n so that a ^ 2 = B. For the two cycles with an length of N, we can find an even number) both B and C can find a loop a with a length of 2n so that a ^ 2 = BC. That is to say, we only need to ensure that the length is an even number and the number is an even number, as for a cyclic decomposition, we can construct a ring by following the directed edge.

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int main () {char B [30]; int vis [30], CNT [30], T; scanf ("% d", & T); While (t --) {scanf ("% s", B ); memset (VIS, 0, sizeof (VIS); memset (CNT, 0, sizeof (CNT); For (INT I = 0; I <26; I ++) if (! Vis [I]) {Int J = I, n = 0; do {vis [J] = 1; j = B [J]-'A'; n ++ ;} while (J! = I); CNT [N] ++;} int flag = 1; for (INT I = 2; I <= 26; I + = 2) if (CNT [I] % 2 = 1) Flag = 0; If (FLAG) printf ("Yes \ n"); else printf ("NO \ n ");} return 0 ;}


Ultraviolet-12103 Leonardo's notebook

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.