题意:给定一个串数,表示一种密码锁,再给定一串密码,问你滑动最少的次数,把第一行变成第二行。

析:很简单么,反正只有0-9这个10个数字,那么就是把每一个数从正着滑和倒着滑中找出一个最小的即可,正着滑就是大数减小数,倒着就是小数+10-大数。

代码如下:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int maxn = 1e3 + 5;
const int INF = 0x3f3f3f3f;
char s[maxn];
char t[maxn]; int main(){
int n;
cin >> n;
scanf("%s", s);
scanf("%s", t);
int ans = 0;
for(int i = 0; i < n; ++i){
int x = s[i] - '0';
int y = t[i] - '0';
ans += min(abs(x-y), (min(x, y)+10-max(x, y))%10);
}
cout << ans << endl;
return 0;
}

CodeForces 540A Combination Lock (水题)的更多相关文章

  1. Codeforces 540A - Combination Lock

    Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he ...

  2. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  3. codeforces 706A A. Beru-taxi(水题)

    题目链接: A. Beru-taxi 题意: 问那个taxi到他的时间最短,水题; AC代码: #include <iostream> #include <cstdio> #i ...

  4. codeforces 569B B. Inventory(水题)

    题目链接: B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces 489A SwapSort (水题)

    A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  6. codeforces 688A A. Opponents(水题)

    题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. CodeForces 534B Covered Path (水题)

    题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...

  8. Codeforces Gym 100286I iSharp 水题

    Problem I. iSharpTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  9. CodeForces 705A(训练水题)

    题目链接:http://codeforces.com/problemset/problem/705/A 从第三个输出中可看出规律, I hate that I love that I hate it ...

随机推荐

  1. 解决jenkins产生的日志过大以及一些衍生问题

          jenkins使用一段时间后,会导致出现比较大的日志问题,经常占满硬盘空间(因为我们使用的硬盘大小20G,无额外存储要求).在硬盘空间占满之后,会导致一些基本的命令都无法使用,譬如tab都 ...

  2. java,js 解unicode

    import java.util.regex.Matcher; import java.util.regex.Pattern; public class UnicodeDecodeDataConver ...

  3. bash中常用的快捷键

    常用快捷键 ctrl+c 强制终止当前命令 ctrl+l 清屏(clear) ctrl+a 光标移动到命令行行首 ctrl+e 光标移动到命令行行尾 ctrl+u 从光标所在位置删除到行首 ctrl+ ...

  4. ubuntu用户添加adduser, useradd并给予sudo权限

    ubuntu用户添加adduser, useradd并给予sudo权限 2016-06-15 10:36 1286人阅读 评论(0) 收藏 举报  分类: Ubuntu(80)  ubuntu和win ...

  5. pycharm git工具与coding.net结合

    前提:coding.net中的项目是私密项目 问题描述:在使用pycharm自带的git工具clone(或者push)代码时出现 错误如下:Push failed: Failed with error ...

  6. Memcached的过期数据的过期机制及删除机制(LRU)

    Memcached的过期数据的过期机制及删除机制1.当某个值过期后,并没有从内存删除,因此,使用stats命令统计时,curr_item参数有信息(不为0)2.当某个新值去占用他的位置时,当成空chu ...

  7. Spring定时器Quartz的使用

    在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等,定时更新某某操作……. 我们可以使用java.util.Timer结合java.util.TimerT ...

  8. iOS学习之UIPickerView控件的关联选择

    接上篇iOS学习之UIPickerView控件的简单使用 接着上篇的代码 http://download.csdn.net/detail/totogo2010/4391870 ,我们要实现的效果如下: ...

  9. Linux常用命令----基本文件系统常用命令

    1.查看当前工作目录---pwd sunny@sunny-ThinkPad-T450:~$ pwd /home/sunny sunny@sunny-ThinkPad-T450:~$ cd Worksp ...

  10. restful返回 json数据的JavaBean设计01

    public class ResponseEntity implements Serializable { private int errCode; private String message; p ...