传送锚点:

codeforces.com

Copy

4 26
bear

output

roar

input

2 7
af

output

db

input

3 1000
hey

output

-1

思路

此题答案不限

有点类似贪心,每一步都要做到最佳,将k不断变小

code

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n, k;//n为单词长度,k为要求的值
cin >> n >> k;
string input;
cin >> input;
string res;//输出答案
for (int i = 0; i < input.size(); i++) {
if(!k){
//这句话不能省略,若还没遍历完input,k就为0,原封不动输出nint
res += input[i];
continue;
}
int x = input[i] - 'a', y = 'z' - input[i];
//x、y可分别理解为到字母a、z的距离
if (x >= y) {
if (x >= k) res += (char)(input[i] - k), k = 0;
//若改为input[i] + k会报错,可能会超了26个字母范围
else k -= x, res += 'a';
}
else {
if (y >= k) res += (char)(input[i] + k), k = 0;
//若改为input[i] - k会报错,可能会超了26个字母范围
else k -= y, res += 'z';
}
}
if (k) cout << -1 << endl;
else cout << res << endl;
return 0;
}

Bear and String Distance的更多相关文章

  1. Codeforces CF#628 Education 8 C. Bear and String Distance

    C. Bear and String Distance time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. CF 628C --- Bear and String Distance --- 简单贪心

    CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...

  3. Educational Codeforces Round 8 C. Bear and String Distance 贪心

    C. Bear and String Distance 题目连接: http://www.codeforces.com/contest/628/problem/C Description Limak ...

  4. codeforces 628C C. Bear and String Distance

    C. Bear and String Distance time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. String Distance and Transform Process

    http://acm.hdu.edu.cn/showproblem.php?pid=1516 Problem Description String Distance is a non-negative ...

  6. hdu 1516 String Distance and Transform Process

    Problem DescriptionString Distance is a non-negative integer that measures the distance between two ...

  7. GO语言的开源库

    Indexes and search engines These sites provide indexes and search engines for Go packages: godoc.org ...

  8. 西南大学校园GIS平台

    系统架构是B/S,开发语言是C#.silverlight,开发平台是.NET,数据库为sqlserver,这是我读研究生时候自己做的作品,以自己的母校为地图,进行GIS相关的功能分析,核心的模块有:空 ...

  9. 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离。显示为公里、米

    /** * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离 * @param array $point_1 第1个点的x,y坐标 array( ...

  10. [简单]docx4j常用方法小结

    http://53873039oycg.iteye.com/blog/2194479?utm_source=tuicool&utm_medium=referral —————————————— ...

随机推荐

  1. Jenkins安装插件很慢的解决方法

    修改 Jenkins /  update  /  default.json  这个文件就可以了 修改内容 1. 把 " www.google.com "  改成  " h ...

  2. 决策树模型(4)Cart算法

    Cart算法 Cart是Classification and regression tree的缩写,即分类回归树.它和前面的ID3, C4.5等算法思想一致都是通过对输入空间进行递归划分并确定每个单元 ...

  3. CentOS 利用pam控制ssh用户的登录及SSH安全配置

    CentOS 利用pam控制ssh用户的登录 有关pam的使用,请找相关的文档.下面只说两个简单的例子. 首先在/etc/pam.d/sshd加入一句: account    required     ...

  4. 重新点亮linux 命令树————su和sudo[七]

    前言 简单整理一下su和sudo这两个命令. 正文 su 这个命令是用来切换用户的. 一般我们切换命令su,还是在原来的路径下面,但是如果想要直接回到切换用户的用户目录的话,可以使用su - user ...

  5. c# webapi swagger

    如何配置swagger? 在使用项目中,我们希望去查看我们的webapi的测试,那么我们是需要去有一个集成的测试的. 步骤 1.在nutget管理包中下载swagger包. 2.这样会在App_sta ...

  6. 深度解读《深度探索C++对象模型》之数据成员的存取效率分析(一)

    接下来我将持续更新"深度解读<深度探索C++对象模型>"系列,敬请期待,欢迎关注!也可以关注公众号:iShare爱分享,自动获得推文和全部的文章列表. 在<深度解 ...

  7. ORA-02303: cannot drop or replace a type with type or table dependents,即无法使用类型或表的相关性来删除或取代一个类型

    ORA-02303: cannot drop or replace a type with type or table dependents,即无法使用类型或表的相关性来删除或取代一个类型 在修改一个 ...

  8. 力扣459(java)-重复的子字符串(简单)

    题目: 给定一个非空的字符串 s ,检查是否可以通过由它的一个子串重复多次构成. 示例 1: 输入: s = "abab"输出: true解释: 可由子串 "ab&quo ...

  9. 云钉一体:EventBridge 联合钉钉连接器打通云钉生态

    ​简介:今天,EventBridge 联合钉钉连接器,打通了钉钉生态和阿里云生态,钉钉的生态伙伴可以通过通道的能力驱动阿里云上海量的计算力. 作者:尘央 背景 "以事件集成阿里云,从 Eve ...

  10. CNCF 沙箱项目 OCM Placement 多集群调度指南

    ​简介:在这篇文章中,将介绍 Placement 如何选择到所需的集群,Placement 可以提供的调度功能,以及一些场景下的最佳实践,使用者可以参考示例来编写符合自己要求的 Placement.其 ...