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. SQL 分组后拼接字符串

    with t as( select 'Charles' parent, 'William' child union select 'Charles', 'Harry' union select 'An ...

  2. [LeetCode] 92. Reverse Linked List II_Medium tag: Linked List

    Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...

  3. java线程池的使用(转)

    在前面的文章中,我们使用线程的时候就去创建一个线程,这样实现起来非常简便,但是就会有一个问题: 如果并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了,这样频繁创建线程就会大大降低系统 ...

  4. kuangbin专题十六 KMP&&扩展KMP HDU3068 最长回文

    给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 回文就是正反读都是一样的字符串,如aba, abba等 Input输入有多组case,不超过120组,每组输入为 ...

  5. HashMap 1.8的源码分析一

    public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, ...

  6. mybatis插入是返回主键id

    <!-- 插入数据:返回记录的id值 --> <insert id="insertOneTest" parameterType="org.chench. ...

  7. STM32F030 定时器多次溢出才触发中断的问题

    前言 最近在调试项目过程中,用了 STM32F030 的定时器 16 作为系统时钟,1ms 触发一次中断,过程中遇到一些值得记录的问题. 记录 STM32F030 中定时器 16 的初始化配置如下 v ...

  8. poj1860 兑换货币(bellman ford判断正环)

    传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. ...

  9. @AutoConfigureAfter不生效 @Configration bean的创建顺序

    https://gooroo.io/GoorooTHINK/Article/17466/Lessons-Learned-Writing-Spring-Boot-Auto-Configurations/ ...

  10. 问题:git处理中文名称时候显示为编码形式(已解决)

    问题描述: Untracked files: (use "git add <file>..." to include in what will be committed ...