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 题目描述 农夫约翰的奶牛不停地从他的农场中逃出来,导致了很多损害.为了防止它们再逃出来,他买了一只很大的号码锁以防止奶牛们打开 ...
随机推荐
- 教你使用 Reflexil 反编译.NET
简介 反编译的方式有很多种,其实最靠谱的还是IL反编译. 如果不懂IL可以尝试我这边文章入门:http://www.wxzzz.com/278.html 不过我下面要说的不是IL这种底层的代码反编译, ...
- IDEA 适用技巧
快速打印 sout - System.out.println(); serr - System.err.println(); //在控制台中是红色的 输入sout,按下enter键,生成System. ...
- Unity3D总结:关于射线碰撞
方法一:Physics.Raycast 光线投射 1.static function Raycast (origin : Vector3, direction : Vector3, distance ...
- kubernetes对象之Volume
系列目录 概述 Volume是对各种存储资源的抽象.虚拟化.为管理.控制.使用存储资源提供统一接口.Openstack中的volume为虚拟机提供存储,Docker中的volume为容器提供存储.因为 ...
- java 回文字符串
package string.string1_5; public class Palindrome { /** * 从两头向中间移动 * @param str * @return */ public ...
- IOS开发之Iphone和Ipad应用程序图标和启动动画
本文转载至 http://blog.csdn.net/yesjava/article/details/8782060 当我们用xcode开发iphone和ipad应用程序的时候,我们可以用一下表中所显 ...
- 基于EasyIPCamera实现的RTSP跨平台拉模式转发流媒体服务器
本文转自博客:http://blog.csdn.net/xinlanbobo/article/details/53224445 上一篇博客<EasyIPCamera通过RTSP协议接入海康.大华 ...
- Open Source Streaming Server--EasyDarwin
Welcome to EasyDarwin Streaming Server, which is an open source Streaming Server Based On Appple's D ...
- File syncing and sharing software with file encryption and group sharing, emphasis on reliability and high performance.
http://seafile.com/ showdoc haiwen/seafile: File syncing and sharing software with file encryption a ...
- Hibernate ManyToOne Mappings 多对一关联映射
Hibernate ManyToOne Mappings 多对一关联映射 Hibernate框架的使用步骤: 1.创建Hibernate的配置文件(hibernate.cfg.xml)2.创建持久化类 ...