这道题写起来没难度,但这种题确实很难,这种字符串的题难在证明。以后也要注意。

奇偶性不同的字符串肯定不能转换,因为每一次交换都是字符串的和增加2。

当字符串长度为2时,可以模拟交换,最多26次。

否则,任选三个字母(x1,x2,x3)->(x1+1,x2,x3+1)......(1)

而且还有(x1,x2,x3)->(x1+2,x2,x3).....(2)

对于第一种变换,可以变换到至多只有一个字母不符合的情况,由于字符串奇偶性相同,则该字母相差为偶数,可以通过第二种变换得到。

#include <iostream>
#include <string.h>
#include <cstring>
#include <cstdio>
using namespace std; char s1[70],s2[70]; int main(){
int T,t=0;
char tmp;
scanf("%d",&T);
while(++t<=T){
scanf("%s",s1);
scanf("%s",s2);
int len=strlen(s1);
printf("Case #%d: ",t);
if(len==2){
int i;
for(i=0;i<26;i++){
tmp=s1[1];
s1[1]=s1[0];
s1[0]=tmp;
s1[0]=(s1[0]-'a'+1)%26+'a';
s1[1]=(s1[1]-'a'+1)%26+'a';
if(strcmp(s1,s2)==0)
break;
}
if(i>=26)puts("NO");
else puts("YES");
}
else{
int sum1=0,sum2=0;
for(int i=0;i<len;i++){
sum1+=(s1[i]-'a');
sum2+=(s2[i]-'a');
}
if(sum1%2==sum2%2)
puts("YES");
else puts("NO");
}
}
return 0;
}

  

HDU 4357的更多相关文章

  1. HDU 4357——String change——————【规律题】

    String change Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. HDU 4357 String change 法冠军

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

  3. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. setResult详解

    startActivityForResult与startActivity的不同之处在于:1.startActivity( ) 仅仅是跳转到目标页面,若是想跳回当前页面,则必须再使用一次startAct ...

  2. tflearn Training Step每次 We will run it for 10 epochs (the network will see all data 10 times) with a batch size of 16. n_epoch=10, batch_size=16

    Training TFLearn provides a model wrapper 'DNN' that can automatically performs a neural network cla ...

  3. nyoj--127--星际之门(一)(生成树的数量)

    星际之门(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门,它 ...

  4. 【POJ 2044】 Weather Forecast

    [题目链接] http://poj.org/problem?id=2044 [算法] 广度优先搜索 [代码] #include <algorithm> #include <bitse ...

  5. HIT Software Construction Lab6引发出来对锁的问题的探究

    前言 做完lab5开始做lab6了鸭,哈工大计算机学院的学生永不停歇.在做lab6的时候,我在想移动猴子是锁一整个ladder(ADT)还是只锁一个ladder的一个域Monkey数组呢?这两个好像差 ...

  6. python print 显示不同的字体

    显示格式: print('\033[显示方式;字体颜色;背景色m.....\033[0m') ------------------------------- 显示方式 | 效果 ----------- ...

  7. Jsoup的简单的使用示例

    利用Jsoup中的相关方法实现网页中的数据爬去,本例子爬去的网页为比较流行的programmableweb中的mashup描述内容,然后为数据库中存在的mashup添加相应的描述. package c ...

  8. MyEclipse设置默认注释的格式

    首先选菜单windows-->preferenceJava-->Code Style-->Code Templates code-->new Java files 然后选中点编 ...

  9. C#泛型类的用途和说明

    class Program    {        public class Test<T, S>        {           //泛型类的类型参数可用于类成员          ...

  10. GCC编译步骤

    gcc -E t1.c -o t1.i 预处理gcc -S t1.i -o t1.s 转成汇编语言gcc -c t1.s -o t1.o 转成机器码gcc t1.o -o t1.exe 链接 直接使用 ...