hdu 4357 String change(推理题,4级)

USACO section 3.4 Closed Fences(计算几何+叉积+二分) Closed Fences A closed fence in the plane is a set of non-crossing, connected line segments with N corners (3 i, yi}, i in (1..N). Every pair of adjacent vertices defines a side of the fence. 阅读详情

String change

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 802    Accepted Submission(s): 370


Problem Description
In this problem you will receive two strings S 1 and S 2 that contain only lowercase letters.
Each time you can swap any two characters of S 1. After swap,both of the two letters will increase their value by one. If the previous letter is 'z',it will become 'a' after being swapped.
That is to say ,"a" becomes "b","b" becomes "c"....."z" becomes "a" and so on.
You can do the change operation in S 1 as many times as you want.
Please tell us whether you can change S 1 to S 2 after some operations or not.
 

Input
There are several cases.The first line of the input is a single integer T (T <= 41) which is the number of test cases.Then comes the T test cases .

For each case,the first line is S 1,the second line is S 2.S 1 has the same length as S 2 and the length of the string is between 2 and 60.
 

Output
For each case,output "Case #X: " first, X is the case number starting from 1.If it is possible change S 1 to S 2 output "YES",otherwise output "NO".
 

Sample Input
  
3 ab ba bac ddb aaabb cbccd
 

Sample Output
  
Case #1: NO Case #2: YES Case #3: YES
Hint
For the first case,it's impossible to change "ab" to "ba" . For the second case,swap(S1[0],S1[2])->swap(S1[1],S1[2]),meanwhile:bac->dac->ddb. For the third case,swap(S1[0],S1[3])->swap(S1[1],S1[2])->swap(S1[2],S1[3])->swap(S1[3],S1[4]), meanwhile:aaabb->caabb->cbbbb->cbccb->cbccd.
 

Author
miketc@UESTC_Goldfinger
 

Source
 

Recommend
zhuyuanchen520

思路:推理后发现超过两张牌的情况,只要是奇偶一样都可以用变换。


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mm=99;
char s[mm],t[mm];
int cas;
int main()
{
  while(~scanf("%d",&cas))
  {
    for(int ca=1;ca<=cas;++ca)
    { scanf("%s%s",s,t);
      printf("Case #%d: ",ca);
      int len=strlen(s);
      bool a=0,b=0;
      bool flag=0;
      int k1,k2;
      if(len==2)
      { k1=(s[0]-t[0]+26)%26;
        k2=(s[1]-t[1]+26)%26;
        if(k1==k2&&k1%2==0)flag=1;
        k1=(s[0]-t[1]+26)%26;
        k2=(s[1]-t[0]+26)%26;
        if(k1==k2&&k1%2==1)flag=1;
        if(flag)printf("YES\n");
        else printf("NO\n");
      }
      else
      {
        for(int i=0;i<len;++i)
        {
          a^=s[i]&1;
          b^=t[i]&1;
        }
        if(a==b)printf("YES\n");
        else printf("NO\n");
      }
    }
  }
  return 0;
}


ROS2节点通信实战:用C++手写一个‘智能小车’控制模型(附完整代码) 本文详细介绍了如何使用ROS2和C++构建一个智能小车控制模型,涵盖运动控制节点、电池管理服务、参数动态配置和Rviz可视化等核心功能。通过实战项目演示ROS2节点通信机制,帮助开发者快速掌握机器人开发的关键技术,并提供了完整的代码实现和系统集成方案。 阅读详情

相关推荐

ZYNQ新手必看:你的PS端DDR和QSPI配置真的对了吗?从原理到实操的避雷指南

本文深入解析ZYNQ PS端外设配置的关键要点,特别是DDR匹配和QSPI时钟优化的实战技巧。通过详细案例和配置清单,帮助开发者避免常见错误,确保系统稳定性和启动可靠性。适合ZYNQ新手和需要优化最小系统的开发者参考。

weixin_28675839的博客 450

字符串调用change方法

小林今天又碰到了一道题,搞明白了跟大家分享一下 下面请看 public class Test{ public static void main(String[] args){ String str=new String('good'); char[] ch={'a','b','c'}; Test ex=new Test(); ...

111会飞的鱼的博客 1万+

openEuler 20.03 LTS面向RK3399移植系列(3)—openEuler 20.03 LTS面向Firefly RK3399的第一个版本(Linux kernel 4.4)

任务动机:完成openEuler面向RK3399开发板的移植。 任务描述:按照固件烧写准备,固件获取,固件打包和烧写的步骤实现openEuler面向RK3399开发板的移植,整理过程和相关命令记录到文档。 1. 制作openEuler的rootfs.img 1.1 开发环境 树莓派--openEuler系统 openEuler 20.03 LTS 的内测版本镜像,下载。 1.2 具体操作 1.2.1 ssh远程连接树莓派 确定树莓派IP ssh连接 1.2.2 制作rootfs.img

火种源码的机器人技术专栏 2382

String重点知识

1.String基本特点 (1)String类是final类,也即意味着String类不能被继承,并且它的成员方法都默认为final方法 (2)String类其实是通过char数组来保存字符串的 (3)String对象一旦被创建就是固定不变的了,对String对象的任何改变都不影响到原对象,相关的任何change操作都会生成新的对象 (4)字面量"+“拼接是在编译期间进行的,拼接后的字符串存放在字...

JonSnow_的博客 295

Proteus 8.9仿真五路抢答器:从74LS148编码到NE555报警的保姆级电路拆解

本文详细解析了使用Proteus 8.9仿真五路抢答器的完整设计流程,从74LS148优先编码器到NE555定时报警电路。通过保姆级的电路拆解和芯片选型指南,帮助读者掌握数字电路中的编码、锁存、译码和定时等核心技术,实现稳定可靠的抢答系统仿真。

weixin_30836759的博客 391

七自由度机械臂逆运动学实战:从几何简化到KDL库高效求解

本文深入探讨了七自由度机械臂逆运动学求解的实战方法。针对冗余自由度带来的挑战,文章对比了两种核心方案:一是利用任务约束进行几何简化,快速求解特定任务;二是基于DH参数法配置KDL库,实现通用高效的数值迭代求解。文中结合宇树H1机器人实例,详细阐述了从模型解析、参数提取到代码实现与验证的全流程,并提供了几何法与KDL库的适用场景对比与避坑指南。

weixin_29044713的博客 651

String为什么无法在方法中修改原有string变量的值

题目 public class Exam10{ String str=new String("good"); char[]ch={'a','b','c'}; public static void main(String args[]){ Exam10 ex=new Exam10(); ex.change(ex.str,ex.ch); System.out.print(ex.str+" and "); System.out.print(ex.ch); }

m0_52410356的博客 1654

Transformer——从原理、模型架构到内部细节介绍

Transformer模型是一种基于注意力机制的深度学习模型,最早由Google在2017年的论文《AttentionIsAllYouNeed》中提出。自其问世以来就迅速席卷了自然语言处理他(NLP)领域,并在各类主流任务上取得了新的突破,包括机器翻译、语言建模、序列标注和文本分类等。在NLP领域取得巨大成功后,迅速扩展到了计算机视觉(CV)领域,并带来了革命性的变化。这种基于自注意力机制的深度学习模型,不仅在NLP任务中力压群雄,也成为CV领域的新宠。

小拉拉的博客 1万+

2021.9.28,内容:string

String类型是final类型,在堆中分配空间后内存地址不可变。 底层是final修饰的char[]数组,数组的内存地址同样不可变。 但实际上可以通过修改char[n] = 'a’来进行修改,不会改变String实例的内存值,不过在jdk中,用户无法直接获取char[],也没有方法能操作该数组。 所以String类型的不可变实际上也是理论上的不可变。所以我们在分配String对象以后,如果将其 = “abc”,那也只是改变了引用的指向,实际上没有改变原来的对象。 StringBuffer和S..

change__12的博客 169

「 网络安全常用术语解读 」软件成分分析SCA详解:从发展背景到技术原理再到业界常用检测工具推荐

软件成分分析(Software Composition Analysis,SCA)是一种用于识别和分析软件内部组件及其关系的技术,旨在帮助开发人员更好地了解和管理其软件的构建过程,同时可帮助安全人员揭秘软件内部结构的神秘面纱。SCA技术的发展与软件行业的快速发展密不可分,下面将介绍SCA的发展背景、技术原理以及当前主流SCA工具。

所有成功的背后,都是痛苦的坚持,所有的痛苦,都是傻瓜般的不放弃! 5653

Full Range && Limit Range

Full Range && Limit Range1 Full range和Limit Range定义2 为什么会需要Limit Range3 用Full range去显示limit Range图片4 YUV转RGB5 额外 1 Full range和Limit Range定义 我们知道,对于RGB和YUV的色彩空间来说,有个位深(bit-depth)的概念;位深是指记录图像每个像素的色彩通道时所使用的bit数,常见的RGB888,YUV420-8bit。以RGB888为例,其代表R G B

zjhcj1的博客 1万+

工控安全政策系列导读:国际标准IEC 62443标准系列

IEC 62443由ANSI/ISA提出,被ISO/IEC采纳,所以该标准会以不同的名字出现,包括:ANSI/ISA-99,ISA-99,ISA 62443,ISO/IEC 62443,ISO 62443,IEC 62443。其中IEC 62443-2-1已等同采纳为国标,于2016年10月发布,标准编号为GB/T 33007。 IEC 62443是在国...

weixin_34132768的博客 2635

string字符串操作

#include<bits/stdc++.h> using namespace std; int main(){ /* string a = "abcdefg"; string b = "abc"; int leng = b.size(); int leng = a.length();//获取字符串长度 printf("%s\n", a.c_s...

ChangeW fafa的博客 302

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

函数change

贴上张图 真心求大神了 public class Exercises5_1 {  String str = new String("Hi !");  char[] ch = { 'L', 'i', 'k', 'e' };  public static void main(String args[]) {  Exercises5_1 ex = new Exercises5_1();  ex.ch...

plpldog的博客 7965

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

深入理解Java中的String

一、String类想要了解一个类,最好的办法就是看这个类的实现源代码,来看一下String类的源码: public final class String implements java.io.Serializable, Comparable&lt;String&gt;, CharSequence { /** The value is used for character stora...

change的博客 635

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hdu---String change

看了解题报告,甚是觉得此题好啊~ 假设有三个字符(x,y,z),可以有以下变化,(x,y,z)->(y+1,x+1,z)->(y+1,z+1,x+2)->(z+2,y+2,x+2)->(如此循环12次)->(z+26,y+26,x+26) == (z,y,x)->(x+1,y,z+1) 同理 (x,y,z)->(x+1,y+1,z);//可以两个同时+1 (x,y,z)->(x+1,y+2,

shuimu12345678的专栏 899

找规律:String Change

String change Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 370    Accepted Submission(s): 166 Problem Description In this problem yo

lethic的专栏 1052

hdu_4357_找字符串规律

String changeIn this problem you will receive two strings S1 and S2 that contain only lowercase letters. Each time you can swap any two characters of S1. After swap,both of the two letters will increa

NITjianbagengmu的博客 354

HDU4357(数学思维题)

题目:String change   把26个字母看成0~25对应的数字,当数慢慢增大时就对26取模,则字符串有一个总和s1,要使其变为末状态的总和s2;那么每交换一次s1要加2,故,s1+s2必须为偶数。两个字母单独处理,两个以上时, 以三个数字为例,(a,b,c)为三个数,则有(a,b,c)->(a,c+1,b+1)->(c+2,,a+1,b+1)->(c再分别 和a,b各交换12次,

ACdreamer 2071

pku 1681 Painter's Problem(高斯消元)

Painter's Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3462   Accepted: 1710 Description There is a square wall which is made of n*n small square br

nealgavin的专栏 1952

pku 1753 Flip Game(高斯消元+枚举)

Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20199   Accepted: 8752 Description Flip game is played on a rectangular 4x4 field with two-sided piec

nealgavin的专栏 1660

hdu 1250 Hat's Fibonacci

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3726    Accepted Submission(s): 1252 Problem Description A Fibonacci se

nealgavin的专栏 1252

nefu702 The minimum square sum(数论)

The minimum square sum Time Limit 1000ms Memory Limit 65536K description   Given a prime p (p8),you are to find min{x2+y2},where x and y belongs t

nealgavin的专栏 1244
上一篇: hdu 4350 Card(递推循环节,3级)
下一篇: hdu 4335 Party All the Time(三分求极值,3级)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址