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 ...
随机推荐
- Linux下安装JRE和Eclipse IDE for C/C++ Developers
Linux32位,下载eclipse-cpp-luna-R-linux-gtk.tar.gz和jre-8u11-linux-i586.rpm 放到家文件夹中. http://www.eclipse. ...
- 最长公共子序列 nlogn
先来个板子 #include<bits/stdc++.h> using namespace std; , M = 1e6+, mod = 1e9+, inf = 1e9+; typedef ...
- Nginx实战系列之功能篇----后端节点健康检查
目前,nginx对后端节点健康检查的方式主要有3种,这里列出: 1.ngx_http_proxy_module 模块和ngx_http_upstream_module模块(自带) 官网地址: ...
- 2015 多校赛 第一场 1002 (hdu 5289)
Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n ...
- javascript中天气接口案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Ajax内容签名技术(减少无谓流量损耗)
UI界面Ajax获取数据内容的时候,一般是直接加载内容填充,不管内容有无变化.自己也是一直这么干,包括定时刷新公告等.今天在浏览器控制台调试的时候,发现动态刷新内容,其实挺耗费流量的,特别是内容无变化 ...
- 三维点集拟合:平面拟合、RANSAC、ICP算法
ACM算法分类:http://www.kuqin.com/algorithm/20080229/4071.html 一: 拟合一个平面:使用SVD分解,代码里面去找吧 空间平面方程的一般表达式为: A ...
- 国外60个专业3D模型网站
原始链接:http://blog.sina.com.cn/s/blog_4ba3c7950100jxkh.html Today, 3D models are used in a wide variet ...
- getopt函数
getopt -- 解析命令的可选项 [说明]getopt只是一个简单的解析命令可选项的函数,只能进行简单的格式命令解析,格式如下: 1.形如:cmd [-a][-b] //对短选项的解析: ...
- 优动漫PAINT用户界面介绍
使用优动漫PAINT能够快速实现工程巨大的漫画.插画以及动画,从13年发布至今一直备受好评,目前优动漫PAINT1.6.6.1是最新的版本,新版本的完善也受到更多年轻伙伴的青睐,使用优动漫PAINT可 ...