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

析:很简单么,反正只有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. web页面取用户控件页面中服务器控件的值

    用户控件页面后台: public string P_Name { get { return txt_P_name.Value; } set { txt_P_name.Value = value; } ...

  2. Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建)

    Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建) 具体案例:局域网内有两台主机,一台Linux.一台Windows,现在需要配置一台Cacti监控服务器对这两台 ...

  3. libvirt- Virsh 所有命令详单

    help            打印帮助    attach-device   从一个XML文件附加装置    attach-disk     附加磁盘设备    attach-interface 获 ...

  4. How To Move a MySQL Data Directory to a New Location on Ubuntu 16.04

    16 How To Move a MySQL Data Directory to a New Location on Ubuntu 16.04 PostedJuly 21, 2016 62.1kvie ...

  5. 13.solr学习速成之IK分词器

    IKAnalyzer简介 IKAnalyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包. IKAnalyzer特性 a. 算法采用“正向迭代最细粒度切分算法”,支持细粒度和最大词长两 ...

  6. CentOS7.6安装稳定版Nginx

    官网地址:http://nginx.org/en/linux_packages.html#RHEL-CentOS 需先安装依赖:sudo yum install -y yum-utils 安装开始: ...

  7. C# GDI+ 实现橡皮筋技术

    原文 C# GDI+ 实现橡皮筋技术 应该有很多人都在寻找这方面的资料,看看下面我做的,或许对你会有所帮助,但愿如此. 为了实现橡皮筋技术,我用了两种方法:     第一种是利用ControlPain ...

  8. AndroidManifest.xml中声明权限——各种permission含义摘录

    android.permission.EXPAND_STATUS_BAR 允许一个程序扩展收缩在状态栏,android开发网提示应该是一个类似Windows Mobile中的托盘程序 android. ...

  9. 在kindeditor 获取textarea 中 输入的值

    要在kindeditor 获取textarea 中 输入的值 必须在kindeditor创建的时候添加下面红色字体的代码     kindeditor创建代码如下: var editor;KindEd ...

  10. Maven中dependencyManagement使用

    在Maven中dependencyManagement的作用其实相当于一个对所依赖jar包进行版本管理的管理器. 在dependencyManagement下申明的dependencies,Maven ...