A - Combination Lock
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of disks on the combination lock.
The second line contains a string of n digits — the original state of the disks.
The third line contains a string of n digits — Scrooge McDuck's combination that opens the lock.
Output
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
Sample Input
Input5
82195
64723Output13Hint
In the sample he needs 13 moves:
- 1 disk:
- 2 disk:
- 3 disk:
- 4 disk:
- 5 disk:
过五反向求,水水。
附AC代码:
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std; int n;
char a[],b[];
int x[],y[]; int main(){
while(cin>>n){
cin>>a>>b;
for(int i=;i<n;i++){
x[i]=a[i]-'';
y[i]=b[i]-'';
}
int sum=;
for(int i=;i<n;i++){
if(abs(x[i]-y[i])>)
sum+=(-abs(x[i]-y[i]));
else
sum+=abs(x[i]-y[i]);
}
cout<<sum<<endl;
}
return ;
}
A - Combination Lock的更多相关文章
- Combination Lock
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...
- hihocoder #1058 Combination Lock
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...
- 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock
题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...
- Codeforces Round #301 (Div. 2) A. Combination Lock 暴力
A. Combination Lock Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/p ...
- Hiho----微软笔试题《Combination Lock》
Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You ...
- CF #301 A :Combination Lock(简单循环)
A :Combination Lock 题意就是有一个密码箱,密码是n位数,现在有一个当前箱子上显示密码A和正确密码B,求有A到B一共至少需要滚动几次: 简单循环:
- hihocoder-第六十一周 Combination Lock
题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview roo ...
- HDU 3104 Combination Lock(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3104 Problem Description A combination lock consists ...
- 洛谷 P2693 [USACO1.3]号码锁 Combination Lock
P2693 [USACO1.3]号码锁 Combination Lock 题目描述 农夫约翰的奶牛不停地从他的农场中逃出来,导致了很多损害.为了防止它们再逃出来,他买了一只很大的号码锁以防止奶牛们打开 ...
随机推荐
- 函数指针使用演示样例(參考Linux-内核代码)
本文有xhz1234(徐洪志)编写,转载请注明出处. http://blog.csdn.net/xhz1234/article/details/36635083 作者:徐洪志 近期阅读Linux-内核 ...
- 简单vi配置:YouCompleteMe
下图就是我的VI: 按F5 F6分别调出左右的窗体: 按C-P点出CtrlP搜索,直接查找project中的文件: 自己主动补全用的YouCompleteMe.超级强悍: watermark/2/te ...
- 28个jQuery性能优化的建议
我一直在寻找有关jQuery性能优化方面的小窍门,能让我那臃肿的动态网页应用变得轻便些.找了很多文章后,我决定将最好最常用的一些优化性能的建议列出来.我也做了一个jQuery性能优化的简明样式表,你可 ...
- EasyDarwin开源流媒体项目
本文转自EasyDarwin CSDN官方博客:http://blog.csdn.net/easydarwin EasyDarwin是由国内开源流媒体团队维护和迭代的一整套开源流媒体视频平台框架,从2 ...
- EasyDarwin开源流媒体服务器提供的TS切片/HLS直播打包库
EasyHLS Github:https://github.com/EasyDarwin/EasyHLS EasyHLS是什么? EasyHLS是EasyDarwin开源流媒体社区开发的一款HLS打 ...
- Ubuntu Firefox没有声音的解决方案
安装ubuntu-restricted-extras sudo apt-get install ubuntu-restricted-extras 参考博文:解决ubuntu中firefox没有声音的问 ...
- Delphi快捷键大全
Delphi快捷键大全 在过程.函数.事件内部, SHIFT+CTRL+向上的方向键 可跳跃到相应的过程.函数.事件的定义.相反,在过程.函数.事件的定义处,SHIFT+CTRL+向下的方向键 可跳跃 ...
- virtualbox Units specified don't exist. SHSUCDX can't install.
version infomatin: virtual box: 5.1.12 platform: win10 x64 target OS: win7 x64 问题 在win10系统上,使用virtua ...
- Python类的特殊属性
Python中的特殊属性 定义如下类: class Foo(object): """Foo class definition""" 类的特殊 ...
- Bestcoder round 18---A题(素数筛+素数打表+找三个素数其和==n)
Primes Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...