Codeforces Round #301 (Div. 2) A. Combination Lock 暴力
A. Combination Lock
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/540/problem/A
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
5
82195
64723
Sample Output
13
HINT
题意
给你一个锁,问你最少转多少下,到达目标态
题解:
暴力转就好了~
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //§ß§é§à§é¨f§³
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int main()
{
string s1,s2;
int n=read();
cin>>s1>>s2;
ll ans=;
for(int i=;i<n;i++)
{
int k=s1[i]-'';
int m=s2[i]-'';
int ans1=;
int ans2=;
while(k!=m)
{
k++;
k%=;
ans1++;
}
k=s1[i]-'';
while(k!=m)
{
k--;
if(k<)
k+=;
ans2++;
}
ans+=min(ans1,ans2);
}
cout<<ans<<endl; }
Codeforces Round #301 (Div. 2) A. Combination Lock 暴力的更多相关文章
- 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock
题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- 贪心 Codeforces Round #109 (Div. 2) B. Combination
题目传送门 /* 贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊! */ #include <cstdio> #include <algorithm> # ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- CodeForces Round #301 Div.2
今天唯一的成果就是把上次几个人一起开房打的那场cf补一下. A. Combination Lock 此等水题看一眼样例加上那个配图我就明白题意了,可是手抽没有注释掉freopen,WA了一发. #in ...
- Codeforces Round #301 (Div. 2)A B C D 水 模拟 bfs 概率dp
A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【解题报告】Codeforces Round #301 (Div. 2) 之ABCD
A. Combination Lock 拨密码..最少次数..密码最多有1000位. 用字符串存起来,然后每位大的减小的和小的+10减大的,再取较小值加起来就可以了... #include<st ...
- Codeforces Round #283 (Div. 2) A ,B ,C 暴力,暴力,暴力
A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- 转: oracle中schema指的是什么?
看来有的人还是对schema的真正含义不太理解,现在我再次整理了一下,希望对大家有所帮助. 我们先来看一下他们的定义:A schema is a collection of database obje ...
- Linux实用命令之git-svn
近日发现了有一个工具,git-svn,可以打通git svn之间的鸿沟. 很适合习惯于git,却需要维护svn代码的同学. 安装 sudo apt-get install git-svn 具体使用就不 ...
- HttpURLConnection传json
private static String sendToWangTing(DataRow dataRow) throws IOException{ String ip = Configuration. ...
- Keras自定义评估函数
1. 比较一般的自定义函数: 需要注意的是,不能像sklearn那样直接定义,因为这里的y_true和y_pred是张量,不是numpy数组.示例如下: from keras import backe ...
- HDU 6198 2017沈阳网络赛 线形递推
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6198 题意:给出一个数k,问用k个斐波那契数相加,得不到的数最小是几. 解法:先暴力打表看看有没有规律 ...
- java基础11 继承(super、extends关键字和重写,这三个要素出现的前提:必须存在继承关系)
面向对象的三大特征: 1.封装 (将一类属性封装起来,并提供set()和get()方法给其他对象设置和获取值.或者是将一个运算方法封装起来,其他对象需要此种做运算时,给此对象调用) 2.继承 ...
- Linux命令参数处理 shell脚本函数getopts
getopts 命令 用途 处理命令行参数,并校验有效选项. 语法 getopts 选项字符串 名称 [ 参数 ...] 描述 getopts 的设计目标是在循环中运行,每次执行循环,getopts ...
- poj 2420(模拟退火)
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6066 Accepted: 285 ...
- 使用亚马逊云服务器EC2做深度学习(四)配置好的系统镜像
这是<使用亚马逊云服务器EC2做深度学习>系列的第四篇文章. (一)申请竞价实例 (二)配置Jupyter Notebook服务器 (三)配置TensorFlow (四)配置好的系统 ...
- 获取对象的key【键】和分别获取数组的key【键】和值
一.先说对象,如何获取key[键]: var obj={ name:"websong", qq:289483936 } 想要获取这个obj对象的键“name”和"qq&q ...