HDU 4357
这道题写起来没难度,但这种题确实很难,这种字符串的题难在证明。以后也要注意。
奇偶性不同的字符串肯定不能转换,因为每一次交换都是字符串的和增加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的更多相关文章
- HDU 4357——String change——————【规律题】
String change Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 4357 String change 法冠军
意甲冠军: 鉴于a串b串,问我们能否a变b串 办法:自选a的2快报,ascil+=1 然后交换位置,能够操作自如倍. 3个月3以上就能T^T 2法官将着眼于暴力 #include <cstdio ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- Android requires compiler compliance level 5.0 or 6.0. Found '1.4' instead的解决的方法
今天在eclipse里报这个错误: Android requires compiler compliance level 5.0 or 6.0. Found '1.4' instead. Plea ...
- 2016.04.03,英语,《Vocabulary Builder》Unit 09
her/hes: from the Latin verb haerere, means 'to stick' or 'to get stuck'. adhesive means 'sticking' ...
- Codeforces Round #349 (Div. 2) C. Reberland Linguistics DP+set
C. Reberland Linguistics First-rate specialists graduate from Berland State Institute of Peace a ...
- actionbarsherlock示例
package com.example.viewpagerandtabdemo; import java.util.ArrayList; import java.util.List; import a ...
- svn代码回滚命令【转】
本文转载自:http://www.cnblogs.com/jndream/archive/2012/03/20/2407955.html 取消对代码的修改分为两种情况: 第一种情况:改动没有被提交 ...
- java javax.annotation.Resource注解的详解
转自:https://www.jb51.net/article/95456.htm java 注解:java javax.annotation.Resource 当我们在xml里面为类配置注入对象时 ...
- jQuery不熟点总结
jQuery 事件 1 .trigger() 方法触发被选元素的指定事件类型. 2 .delegate() 事件委派 1.不占内存2.可以给未来元素(后期动态添加的元素)添加事件. 2. 添加元 ...
- golang iris html/temple
在使用golang的模板语法的过程中遇见自动转义问题(或者以我的理解下发的富文本html代码不是template.html类型,而是string类型),需要强制转型 func unescaped(x ...
- 常用GC算法
在C/C++中是由程序员自己去申请.管理和释放内存的,因此没有GC的概念.而在Java中,专门有一个用于垃圾回收的后台线程来进行监控.扫描,自动将一些无用的内存进行释放.下面介绍几种常见的GC算法. ...
- WPF MVVM 关闭窗体
由于程序采用MVVM模式同时有些操作需要单独窗口来进行处理.因此就会产生窗口关闭问题, 由于是MVVM和需要操作弹出窗口中操作的内容因此就需要在mvvm进行统一处理. 网上查了几种方法采用其中一种 不 ...