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

奇偶性不同的字符串肯定不能转换,因为每一次交换都是字符串的和增加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. Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-3.0.xsd)

    问题: java项目在Eclipse中xml有小红叉 Problems:Referenced file contains errors (http://www.springframework.org/ ...

  2. DDos攻击的一些领域知识——(流量模型针对稳定业务比较有效)不稳定业务采用流量成本的检测算法,攻击发生的时候网络中各个协议的占比发生了明显的变化

    在过去,很多防火墙对于DDoS攻击的检测一般是基于一个预先设定的流量阈值,超过一定的阈值,则会产生告警事件,做的细一些的可能会针对不同的流量特征设置不同的告警曲线,这样当某种攻击突然出现的时候,比如S ...

  3. Node.js:工具模块

    ylbtech-Node.js:工具模块 1.返回顶部 1. Node.js 工具模块 在 Node.js 模块库中有很多好用的模块.接下来我们为大家介绍几种常用模块的使用: 序号 模块名 & ...

  4. 搭建自己的websocket server_1

    用Node.js实现一个WebSocket的Server. https://github.com/sitegui/nodejs-websocket#event-errorerr   nodejs-we ...

  5. linux git保存用户名密码(避免每次push输用户名密码)

    Linux/Unix/Mac 系统 新建一个 ~/.netrc 文件, 将 git 服务器, 用户名以及密码记录在这个文件, 如下所示:   machine your-git-server   log ...

  6. guice基本使用,常用的绑定方式(四)

    guice在moudle中提供了良好的绑定方法. 它提供了普通的绑定,自定义注解绑定,按名称绑定等. 下面直接看代码: package com.ming.user.test; import com.g ...

  7. 使用Micrisoft.net设计方案 前言

    前言 主要阐述23种设计模式在Microsoft.Net中的使用,以及使用设计模式创建后的对象如何使用.同是向我们传达3个理念,分别是: 1.  使用设计模式可以让程序更加灵活 2.  结构越复杂,意 ...

  8. spring IOC(DI)和AOP

    软件152谭智馗 IOC(Inversion of Control,控制倒转)Ioc意味着将你设计好的对象交给容器控制,而不是传统的在你的对象内部直接控制. DI—Dependency Injecti ...

  9. asp、asp.net、ado、ado.net各自区别和联系?

    asp.net与ado.net 的区别? asp.net是微软公司的.Net技术框架下的B/S(网页方向)框架技术.ado.net则是由asp.net编程语言编写的数据访问层的总括..说白了就是:as ...

  10. equal height

    https://css-tricks.com/the-perfect-fluid-width-layout/ http://nicolasgallagher.com/multiple-backgrou ...