B. You Are Given a Decimal String...

这个题需要求出从某一个尾数 n 变为 m 所需要的 x 和 y 的最小个数(i+j) 那么就需要预处理出一个数组来存放这个值。数组 b[ ] 中存的是所需要多添加的数的个数 (i+j-1)

int b[10];
for (int i = 0; i < 10; ++i) b[i] = inf;
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
{
if (i || j)
b[(i * x + j * y) % 10] = min(b[(i * x + j * y) % 10], i+j-1);
//i+j-1是需要多添加的数的个数
}

代码:

// Created by CAD on 2019/8/9.
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f using namespace std; int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
for (int x = 0; x < 10; ++x)
for (int y = 0; y < 10; ++y)
{
int b[10];
for (int i = 0; i < 10; ++i) b[i] = inf;
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
{
if (i || j)
b[(i * x + j * y) % 10] = min(b[(i * x + j * y) % 10], i + j - 1);
}
int ans = 0;
for (int i = 0; s[i + 1] != '\0'; ++i)
if (b[(s[i + 1] - s[i] + 10) % 10] == inf)
{
ans = -1;
break;
} else ans += b[(s[i + 1] - s[i] + 10) % 10];
cout << ans;
if (y == 9) cout << endl;
else cout << " "; }
return 0;
}

You Are Given a Decimal String...的更多相关文章

  1. [最短路,floyd] Codeforces 1202B You Are Given a Decimal String...

    题目:http://codeforces.com/contest/1202/problem/B B. You Are Given a Decimal String... time limit per ...

  2. You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]

    补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...

  3. (模拟)关于进制的瞎搞---You Are Given a Decimal String...(Educational Codeforces Round 70 (Rated for Div. 2))

    题目链接:https://codeforc.es/contest/1202/problem/B 题意: 给你一串数,问你插入最少多少数可以使x-y型机器(每次+x或+y的机器,机器每次只取最低位--% ...

  4. [CF1202B] You Are Given a Decimal String(最短路)

    Description 今天突然想来发一篇博客防死 [Portal][https://vjudge.net/problem/2650668/origin] 定义被x-y生成器生成的序列为, 一开始有一 ...

  5. JS转换Decimal带千分号的字符串显示

    var numberChars = "0123456789"; /* Convert to decimal string */ function toDecimalString(v ...

  6. String类的一些常用操作方法

    package com.liveyc.framework.util; import java.io.UnsupportedEncodingException; import java.net.URLD ...

  7. ESQL 查询数据报 参数类型“Edm.Decimal”和“Edm.Double”不兼容

    ESQL 查询数据报 参数类型“Edm.Decimal”和“Edm.Double”不兼容 System.Data.Entity.Core.Objects.ObjectQuery<TEntity& ...

  8. 背后的故事之 - 快乐的Lambda表达式(一)

    快乐的Lambda表达式(二) 自从Lambda随.NET Framework3.5出现在.NET开发者眼前以来,它已经给我们带来了太多的欣喜.它优雅,对开发者更友好,能提高开发效率,天啊!它还有可能 ...

  9. Dev统计选中行、如需其他数据源可留言

    Clipboard.Clear(); Dictionary<string, decimal> dtary = new Dictionary<string, decimal>() ...

随机推荐

  1. Luogu P4436 [HNOI/AHOI2018]游戏

    题目 我们要求出\(l_i,r_i\)表示\(i\)最远能够到达的最左边和最右边的格子. 首先有一个比较简单的暴力,就是每次我们选择一个格子,然后从当前格子开始往左右暴力扩展,找到能够到达的最远的格子 ...

  2. python网络编程-socket套接字通信循环-粘包问题-struct模块-02

    前置知识 不同计算机程序之间数据的传输 应用程序中的数据都是从程序所在计算机内存中读取的. 内存中的数据是从硬盘读取或者网络传输过来的 不同计算机程序数据传输需要经过七层协议物理连接介质才能到达目标程 ...

  3. LoadRunner之使用JSEESIONID访问网站

    LoadRunner使用笔记 JSESSIONID的含义:https://www.cnblogs.com/caiwenjing/p/8081391.html 1.使用JSESSIONID访问网站 Ac ...

  4. golang(2):基本数据类型和操作符

    1). 文件名 & 关键字 & 标识符 . 所有go源码都以 .go 结尾 . 标识符以字母或下划线开头,大小写敏感 . _ 是特殊标识符,用来忽略结果 . 保留关键字 golang  ...

  5. [转载]C++之using namespace std 详解与命名空间的使用

    来源:https://blog.csdn.net/Bruce_0712/article/details/72824668 所谓namespace,是指标识符的各种可见范围.C++标准程序库中的所有标识 ...

  6. k8s弹性伸缩概念以及测试用例

    k8s弹性伸缩概念以及测试用例 本文原文出处:https://juejin.im/post/5c82367ff265da2d85330d4f 弹性伸缩式k8s中的一大亮点功能,当负载大的时候,你可以对 ...

  7. 转:spring中InitailizingBean接口的简单理解

    转自:https://www.cnblogs.com/wxgblogs/p/6849782.html spring中InitializingBean接口使用理解   InitializingBean接 ...

  8. 多线程编程-- part 6 共享锁和ReentrantReadWriteLock

    介绍: ReadWriteLock,顾名思义,是读写锁.它维护了一对相关的锁 — — “读取锁”和“写入锁”,一个用于读取操作,另一个用于写入操作.(1)“读取锁”用于只读操作,它是“共享锁”,能同时 ...

  9. Codeforces Round #344 (Div. 2) 631 B. Print Check (实现)

    B. Print Check time limit per test1 second memory limit per test256 megabytes inputstandard input ou ...

  10. Zookeeper客户端使用(使用Curator)

    Zookeeper客户端(使用Curator) 三.使用curator客户端 在pom.xml中加入依赖 <dependency> <groupId>org.apache.cu ...