String change
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1116 Accepted Submission(s): 494
Each time you can swap any two characters of S 1. After swap,both of the two letters will increase their value by one. If the previous letter is 'z',it will become 'a' after being swapped.
That is to say ,"a" becomes "b","b" becomes "c"....."z" becomes "a" and so on.
You can do the change operation in S 1 as many times as you want.
Please tell us whether you can change S 1 to S 2 after some operations or not.
For each case,the first line is S 1,the second line is S 2.S 1 has the same length as S 2 and the length of the string is between 2 and 60.
把26个字母看成0~25对应的数字,当数慢慢增大时就对26取模,则字符串有一个总和s1,要使其变为末状态的总和s2;那么每交换一次s1要加2,故,s1+s2必须为偶数。
两个字母单独处理,两个以上时,以三个数字为例,(a,b,c)为三个数,则有(a,b,c)->(a,c+1,b+1)->(c+2,,a+1,b+1)->(c再分别和a,b各交换12次,有(c+26,a+13,b+13),再a,b相互交换13次得(c+26,b+26,a+26);而26为一个周期,即39次交换后由(a,b,c)->(c,b,a)(中间不动,两边交换了);同理可证39次交换后,可由(a,b,c)->(b,a,c)(一边不动,相邻的交换);因此,一开始可任意按需要进行交换使s1中的各数与s2中的各数相等,再进行调位置。如果是两个数就不一样了,设要由(a1,a2)->(b1,b2),则a1必经偶数变为b1或经奇数步变为b2;又由于26步之后a1,a2又会变回原状态,故必在26步之内要解决变形,先设a1变形成功,再只须检查a2有没有变形成功即可