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

析:很简单么,反正只有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. 【BZOJ】1012: [JSOI2008]最大数maxnumber /【洛谷】1198(线段树)

    Description 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2. 插 ...

  2. android.support.v4.app.Fragment vs android.app.Fragment 的区别

    android.support.v4.app.Fragment vs android.app.Fragment 的区别 我开过平板相关应用,用了Fragment来处理.后来重新开发另外一个应用,直接引 ...

  3. poj2356 Find a multiple

    /* POJ-2356 Find a multiple ----抽屉原理 Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total S ...

  4. 解决IIS无响应假死状态

    方法一: 临时解决办法:在IIS中选择你的网站,右击->属性,选择主目录选项卡,最下面有个应用程序池选项,记住该处的名字,然后在IIS中找到应用程序池并展开,选择你刚才看到的那个名字,右击-&g ...

  5. 【框架】Spring和dubbox

    分布式服务框架 dubbo/dubbox 入门示例 https://www.cnblogs.com/yjmyzz/p/dubbox-demo.html 初识Spring Boot框架 https:// ...

  6. 【转】Android编码规范建议18条

    转自:http://www.chinaz.com/design/2015/0908/443732.shtml Android编码规范建议18条 适合手机app设计师和android 工程师阅读. 1. ...

  7. C# 提取方法重构

    引用:https://msdn.microsoft.com/zh-CN/library/0s21cwxk.aspx “提取方法”是一项重构操作,提供了一种从现有成员中的代码段创建新方法的便捷方式. 使 ...

  8. python操作docx文档(转)

    python操作docx文档 关于python操作docx格式文档,我用到了两个python包,一个便是python-docx包,另一个便是python-docx-template;,同时我也用到了很 ...

  9. UNITY IMGUI

    这几天研究OPENGL时,想找一个UI库来用,发现了IMGUI,到网上搜索评估中,突然发现它似乎和UNITY有关系. UNITY文档中提到过IMGUI,不知道是不一个东西,仔细看了下文档,果然是.原文 ...

  10. JQuery easyUi datagrid 中 editor 动态设置最大值最小值

    前言 近来项目中使用到 easyui 来进行页面设计,感觉挺方便的,但是网上除了api外,其他有价值的资料比较少,故在此分享一点经验,供大家参考.   问题 JQuery easyUi datagri ...