String change

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1116    Accepted Submission(s): 494

Problem Description
In this problem you will receive two strings S1 and S2 that contain only lowercase letters.
Each time you can swap any two characters of S1. 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 S1 as many times as you want.
Please tell us whether you can change S1 to S2 after some operations or not.
 
Input
There are several cases.The first line of the input is a single integer T (T <= 41) which is the number of test cases.Then comes the T test cases .

For each case,the first line is S1,the second line is S2.S1 has the same length as S2 and the length of the string is between 2 and 60.

 
Output
For each case,output "Case #X: " first, X is the case number starting from 1.If it is possible change S1 to S2 output "YES",otherwise output "NO".
 
Sample Input
3
ab
ba
bac
ddb
aaabb
cbccd
 
Sample Output
Case #1: NO
Case #2: YES
Case #3: YES

Hint

For the first case,it's impossible to change "ab" to "ba" .

For the second case,swap(S1[0],S1[2])->swap(S1[1],S1[2]),meanwhile:bac->dac->ddb.

For the third case,swap(S1[0],S1[3])->swap(S1[1],S1[2])->swap(S1[2],S1[3])->swap(S1[3],S1[4]),
meanwhile:aaabb->caabb->cbbbb->cbccb->cbccd.

 
Author
miketc@UESTC_Goldfinger
 
Source
 
 
题目大意:给你两个串s和t。让你判断是否可以从s转化到t。转化规则是你可以无限次交换任意两个字符,然后两个字符的值会+1。相应变化a -> b 、 b -> c 、z -> a。
 

把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有没有变形成功即可

 

HDU 4357——String change——————【规律题】的更多相关文章

  1. HDU 4357 String change 法冠军

    意甲冠军: 鉴于a串b串,问我们能否a变b串 办法:自选a的2快报,ascil+=1 然后交换位置,能够操作自如倍. 3个月3以上就能T^T 2法官将着眼于暴力 #include <cstdio ...

  2. HDU 4937 Lucky Number 规律题_(:зゝ∠)_

    把全部合法的进制打出来会发现合法的进制都是在 n/3 n/4 n/5的边上 然后暴力边上的进制数.. #include <cstdio> #include <set> type ...

  3. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  4. hdoj--1005--Number Sequence(规律题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. LightOJ1010---Knights in Chessboard (规律题)

    Given an m x n chessboard where you want to place chess knights. You have to find the number of maxi ...

  6. Codeforces - 规律题 [占坑]

    发现自己容易被卡水题,需要强行苟一下规律题 CF上并没有对应的tag,所以本题集大部分对应百毒搜索按顺序刷 本题集侧重于找规律的过程(不然做这些垃圾题有什么用) Codeforces - 1008C ...

  7. ACM_送气球(规律题)

    送气球 Time Limit: 2000/1000ms (Java/Others) Problem Description: 为了奖励近段时间辛苦刷题的ACMer,会长决定给正在机房刷题的他们送气球. ...

  8. hdu 4722 Good Numbers(规律题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4722 [题意]: 找GoodNumbers一个数N,如果它每一个位数字之和可以整除10,那么它就是GoodNum ...

  9. HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...

随机推荐

  1. C# 三元运算

    x=,y=; z=x>y? : 结果z= x=,y=; z=x>y? : 结果z=

  2. CodeSmith链接MySQL

    环境:Win7 x64 旗舰版 CodeSmith Generator Professional 6.5.0 MySQL 5.6.17 x64 在CodeSmith中按一般步骤创建数据库连接 Data ...

  3. ubuntu - 常用问题解决命令

    查看本机网络通畅 - 网络是否可连接(远程链接时,检验防火墙) ping -c 10 localhost 查看本机进程/端口占用情况(看某一进程是否开启) netstat -tln 具体查看某一进程 ...

  4. [Study notes] To programing RGBD-SLAM together from Gaoxiang

    Solve CMake Error in CMakeLists.txt (FIND_PAKAGE): CMake Error at src/CMakeLists.txt:5 (FIND_PACKAGE ...

  5. django 学习之DRF (二)

    Django学习之DRF02 Serializer序列化器之反序列化操作    1.调⽤序列化器进⾏验证        0.准备序列化器 class BookInfoSerializer(serial ...

  6. (vue.js)import "mint-ui/lib/stylecss"失败

    在vue2.0中引入了mint-ui后总是报一个css的错误 但是package.json中已经配置了css-loader style-loader ,webpack.config中也已经配置了css ...

  7. ajax遍历数据生成下拉框

    <script type="text/javascript">        function GetEQIDList(ModuleID)    {        $. ...

  8. iOS 11导航栏设置BarButtonItem变形问题和错位问题

    升级到 iOS 11,你可能会发现你的 App 的工具栏的行为出了点异常.比如奇点,我在使用过程中,发现工具栏时灵时不灵,感觉很难点到.这是怎么回事?通过 Xcode 的 Debug View Hie ...

  9. C语言使用指针表示数组的注意事项

    1)数组名是指针常量 如对指针变量可以进行++运算,但是对数组名却不允许,另外,对数组名的赋值运算也是错误的 2)注意指针变量的当前值 指针变量的值在程序运行过程中可能经常改变,要对此注意 3)数组越 ...

  10. 解决SharePoint密码更新后,创建Web Application 失败

    问题在sharepoint central administration中通过Configuration Wizards来创建一个web application,出现如下错误: The passwor ...