• Codeforces Round #377 (Div. 2) A. Buy a Shovel【暴力/口袋里面有无限枚 10 元和一枚 r 面值的硬币,问最少可以买多少把价值为 k 的铁铲】


    A. Buy a Shovel
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.

    In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ≤ 9).

    What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of r burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.

    Input

    The single line of input contains two integers k and r (1 ≤ k ≤ 1000, 1 ≤ r ≤ 9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".

    Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.

    Output

    Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.

    Examples
    input
    117 3
    output
    9
    input
    237 7
    output
    1
    input
    15 2
    output
    2
    Note

    In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.

    In the second example it is enough for Polycarp to buy one shovel.

    In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.

    【题意】:口袋里面有无限枚 10 元和一枚 r 面值的硬币,问最少可以买多少把价值为 k 的铁铲。

    【分析】:模拟。倍增k,直到为10的倍数(无限10元支付)或者减掉r后为10倍数。

    【代码】:

    #include <bits/stdc++.h>
    
    using namespace std;
    int main()
    {
        int r,k,sum;
        while(cin>>k>>r)
        {
            sum=0;
            for(int i=1;;i++)
            {
                sum=k*i;
                if(sum%10==0||(sum-r)%10==0)
                {
                    printf("%d
    ",i);
                    break;
                }
            }
        }
        return 0;
    }
    View Code

     

  • 相关阅读:
    中层人才轮岗,张勇宣布阿里新一轮组织架构调整
    公司倒闭 1 年了,而我当年的项目上了 GitHub 热榜
    为什么别人的行业都那么让人羡慕
    ClickHouse 高级(五)数据一致性(重点)
    ClickHouse 高级(四)优化(4)查询优化
    ClickHouse 高级(二)优化(2)建表优化
    ClickHouse 高级(一)优化(1)Explain 查看执行计划
    ClickHouse基础(八)使用基础(5)ClickHouse 的安装(win10)
    【简单的原创】div简单轮换显示
    BZOJ 5494: [2019省队联测]春节十二响 (左偏树 可并堆)
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7942975.html
Copyright © 2020-2023  润新知