Anagram(山东省2018年ACM浪潮杯省赛)
Problem Description
Orz has two strings of the same length: A and B. Now she wants to transform A into an anagram of B (which means, a rearrangement of B) by changing some of its letters. The only operation the girl can make is to “increase” some (possibly none or all) characters in A. E.g., she can change an 'A' to a 'B', or a 'K' to an 'L'. She can increase any character any times. E.g., she can increment an 'A' three times to get a 'D'. The increment is cyclic: if she increases a 'Z', she gets an 'A' again.
For example, she can transform "ELLY" to "KRIS" character by character by shifting 'E' to 'K' (6 operations), 'L' to 'R' (again 6 operations), the second 'L' to 'I' (23 operations, going from 'Z' to 'A' on the 15-th operation), and finally 'Y' to 'S' (20 operations, again cyclically going from 'Z' to 'A' on the 2-nd operation). The total number of operations would be 6 + 6 + 23 + 20 = 55. However, to make "ELLY" an anagram of "KRIS" it would be better to change it to "IRSK" with only 29 operations. You are given the strings A and B. Find the minimal number of operations needed to transform A into some other string X, such that X is an anagram of B.
Input
There will be multiple test cases. For each test case:
There is two strings A and B in one line.|A| = |B| \leq 50∣A∣=∣B∣≤50. A and B will contain only uppercase letters from the English alphabet ('A'-'Z').
Output
For each test case, output the minimal number of operations.
Sample Input
ABCA BACA
ELLY KRIS
AAAA ZZZZ
Sample Output
0
29
100 水题 字符串匹配
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
string s1,s2;
int a[];
while(cin>>s1>>s2){
int minn = ,cnt = ,k = ,ans = ;
memset(a,,sizeof(a));
int l = s1.length();
for(int i=;i<l;i++)
{
minn = ;
for(int j=;j<l;j++){
if(a[j] == ){
if( s1[i] <= s2[j]){
cnt = (s2[j]-'A') - (s1[i]-'A');
}
else{
cnt = - ((s1[i]-'A') - (s2[j]-'A'));
}
if(cnt < minn){
minn = cnt;
k = j;
}
}
}
ans += minn ;
a[k] = ;
}
cout<<ans<<endl;
}
return ;
}
Anagram(山东省2018年ACM浪潮杯省赛)的更多相关文章
- [ACM]2013山东省“浪潮杯”省赛 解题报告
题目地址:http://acm.upc.edu.cn/problemset.php?page=13 2217~2226 A.Rescue The Princess 一个等边三角形告诉前2个点,求逆时 ...
- 2013山东省“浪潮杯”省赛 A.Rescue The Princess
A.Rescue The PrincessDescription Several days ago, a beast caught a beautiful princess and the princ ...
- Shopping(山东省第一届ACM省赛)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- 2018.10.19浪在ACM 集训队第一次测试赛
2018.10.19浪在ACM 集训队第一次测试赛 待参考资料: [1]:https://blog.csdn.net/XLno_name/article/details/78559973?utm_so ...
- 第九届蓝桥杯国赛+第二天的第11届acm省赛的总结
第九届蓝桥杯国赛+第二天的第11届acm省赛的总结 25号坐的去北京的火车,10个小时的火车,然后挤了快两个小时的地铁,最终达到了中国矿业大学旁边的订的房间.12个小时很难受,晕车症状有点严重,吃了快 ...
- 华东交通大学2018年ACM“双基”程序设计竞赛 C. 公式题 (2) (矩阵快速幂)
题目链接:公式题 (2) 比赛链接:华东交通大学2018年ACM"双基"程序设计竞赛 题目描述 令f(n)=2f(n-1)+3f(n-2)+n,f(1)=1,f(2)=2 令g(n ...
- 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)
队名:Unlimited Code Works(无尽编码) 队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...
- 52-2018 蓝桥杯省赛 B 组模拟赛(一)java
最近蒜头君喜欢上了U型数字,所谓U型数字,就是这个数字的每一位先严格单调递减,后严格单调递增.比如 212212 就是一个U型数字,但是 333333, 9898, 567567, 313133131 ...
- 计蒜客蓝桥杯模拟赛 后缀字符串:STL_map+贪心
问题描述 一天蒜头君得到 n 个字符串 si,每个字符串的长度都不超过 10. 蒜头君在想,在这 n 个字符串中,以 si 为后缀的字符串有多少个呢? 输入格式 第一行输入一个整数 n. 接下来 ...
随机推荐
- OpenCV Machine Learning 之 正态贝叶斯分类器 (Normal Bayes Classifier)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zhjm07054115/article/details/27631913
- 应用索引技术优化SQL 语句(转)
原文出处 一.前言 很多数据库系统性能不理想是因为系统没有经过整体优化,存在大量性能低下的SQL 语句.这类SQL语句性能不好的首要原因是缺乏高效的索引.没有索引除了导致语句本身运行速度慢外,更是导致 ...
- Android/iOS Remote debugging
简单介绍 使用下面方法可以定位webview中的元素,无法定位view中的元素. 原文地址:http://mp.weixin.qq.com/s/y_UfdgjT_pkKgYivJmqt7Q webvi ...
- Redis shell
Redis shell 命令 参数 功能 redis-cli -r 将一个命令执行多次 -i 每隔几秒执行一次 -x 和|一起接收前面地输出,并执行命令 -c -a --scan/--patt ...
- VMware和Centos系统安装
1.Linux发行版的选择 2.vmware创建一个虚拟机(centos) 3.安装配置centos7 4.xshell配置连接虚拟机(centos) 选择性 pc可以选择 -纯系统 Linux/wi ...
- Redis- 内存数据库Redis之安装部署
内存数据库Redis之安装部署 Redis是一款非关系型,key-value存储的内存数据库,Redis数据库完全在内存中,使用磁盘仅用于持久性.Redis的速度非常快,每秒能执行约11万集合,每秒约 ...
- redis数据
毫无疑问,Redis开创了一种新的数据存储思路,使用Redis,我们不用在面对功能单调的数据库时,把精力放在如何把大象放进冰箱这样的问题上,而是利用Redis灵活多变的数据结构和数据操作,为不同的大象 ...
- leetcode 66. Plus One(高精度加法)
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- POJ3728The merchant (倍增)(LCA)(DP)(经典)(||并查集压缩路径?)
There are N cities in a country, and there is one and only one simple path between each pair of citi ...
- MySQL-计算当月重新激活客户_20161013
13号的草稿 12号的明天补充更新,最近太忙了. 客户留存率是衡量客户价值经常用的指标,可以反映客户的活跃程度,在互联网企业,尤其是现在手机端流量已经超过PC端流量,在安卓和IOS设备上在线时长的数据 ...