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. 接下来 ...
随机推荐
- jQuery的事件绑定和解除
1 . 绑定事件 语法 : bind(type,data,fn) 描述 : 为每一个匹配的特定元素(像 click)绑定一个事件处理器函数. type(String) : 事件类型 data(Obje ...
- BZOJ 2819 Nim 树链剖分+树状数组
这题真没什么意思. 不过就是将普通的求Min,Max,求和等东西换成Xor,偏偏Xor还有很多性质. 算是刷道水题吧. #include<iostream> #include<cst ...
- Linux--struct file结构体【转】
本文转载自:https://www.cnblogs.com/hanxiaoyu/p/5677677.html struct file(file结构体): struct file结构体定义在includ ...
- ManualResetEvent使用
1.定义 MSDN定义: 通知一个或多个正在等待的线程已发生事件.此类不能被继承. 详细说明: ManualResetEvent 允许线程通过发信号互相通信.通常,此通信涉及一个线程在其他线程进行之前 ...
- MySQL存储过程示例
MySQL存储过程: /*自定义结束符*/ DELIMITER $$ /*如果存在同名的存储过程就删除*/ DROP PROCEDURE IF EXISTS prAddBlack$$ /*创建存储过程 ...
- 理解多线程中的ManualResetEvent(C#)
线程是程序中的控制流程的封装.你可能已经习惯于写单线程程序,也就是,程序在它们的代码中一次只在一条路中执行.如果你多弄几个线程的话,代码运行可能会更加“同步”.在一个有着多线程的典型进程中,零个或更多 ...
- struts2 validate手动验证
我们前面学习struts2知道,struts2通过拦截器实现了一些验证操作. 比如,如果是不能转换的类型在action中接受的话会跳转到错误页面,错误信息中会包含对应的错误信息,例如: 首先我们了解一 ...
- POJ3417Network(LCA+树上查分||树剖+线段树)
Yixght is a manager of the company called SzqNetwork(SN). Now she's very worried because she has jus ...
- [Poi2011] Meteors(从不知所措到整体二分)
Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The plan ...
- BZOJ_2467_[中山市选2010]生成树_数学
BZOJ_2467_[中山市选2010]生成树_数学 [Submit][Status][Discuss] Description 有一种图形叫做五角形圈.一个五角形圈的中心有1个由n个顶点和n条边组成 ...