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 ...
随机推荐
- bzoj4465: [Jsoi2013]游戏中的学问
DP 一个人要么加入一个圈,要么三个人开一圈 #include<cstdio> #include<iostream> #include<cstring> #incl ...
- Dragon Ball--hdoj
Dragon Ball Problem Description Five hundred years later, the number of dragon balls will increase u ...
- 二、SQL系列之~常见51道SQL查询语句
[写在前面~~] [PS1:建议SQL初学者一定要自己先做一遍题目,这样才有效果~~(做题时为验证查询结果是否正确,可更改表中数据)] [PS2:文末最后一条代码整合了全部51道题目及答案~~] [P ...
- FastDFS介绍(非原创)
文章大纲 一.FastDFS介绍二.FastDFS安装与启动(Linux系统)三.Java客户端上传图片四.参考文章 一.FastDFS介绍 1. 什么是FastDFS FastDFS是用C语言编 ...
- 利用jquery的ajaxPrefilter阻止重复发送请求
利用jquery的ajaxPrefilter阻止重复发送请求 (function ($) { var pendingRequests = {}; // 所有ajax请求的通用前置filter $.aj ...
- python课程设计笔记(五) ----Resuests+BeautifulSoup (爬虫入门)
官方参考文档(中文版): requests:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html beautifulsou ...
- Redis之Ubuntu下Redis集群搭建
安装redis 首先下载redis $ wget http://download.redis.io/releases/redis-4.0.10.tar.gz $ .tar.gz $ cd redis- ...
- jQuery操作样式知识总结
css操作 功能:设置或者修改样式,操作的是style属性. 设置单个样式 //name:需要设置的样式名称 //value:对应的样式值 css(name, value); //使用案例 $(&qu ...
- 23个Python爬虫开源项目代码:爬取微信、淘宝、豆瓣、知乎、微博等
来源:全球人工智能 作者:SFLYQ 今天为大家整理了23个Python爬虫项目.整理的原因是,爬虫入门简单快速,也非常适合新入门的小伙伴培养信心.所有链接指向GitHub,祝大家玩的愉快 1.Wec ...
- nodejs supervisor安装
使用supervisor提高nodejs调试效率 用超级用户运行npm -g install supervisor命令,说是顺 >$ sudo npm -g install supervisor ...