zoukankan      html  css  js  c++  java
  • 【71.76%】【codeforces 732A】Buy a Shovel

    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard 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.

    【题解】

    枚举要买j个Shovel就好;
    j*price 或者j*price-r 如果%10==0则输出
    (从1到10枚举)

    #include <cstdio>
    
    int k, r;
    
    int main()
    {
        //freopen("F:\rush.txt", "r", stdin);
        scanf("%d%d", &k, &r);
        for (int i = 1; i <= 10; i++)
        {
            int temp = i*k;
            int temp1 = temp - r;
            if ((temp % 10) == 0 || (temp1%10)==0)
            {
                printf("%d
    ", i);
                return 0;
            }
        }
        return 0;
    }
  • 相关阅读:
    58:二叉树的下一个节点
    57:删除链表中重复的结点
    56:链表中环的入口结点
    55:字符流中第一个不重复的字符
    54:表示数值的字符串
    53:正则表达式匹配
    52:构建成绩数组
    51:数组中重复的数字
    每个努力奋斗过的人,被不公正的际遇砸了满头包的时候,都有那么一瞬间的代入感。出生就是hard模式的人,早已经历了太多的劳其筋骨饿其体肤,再多的人为考验只会摧毁人对美好的向往。
    ClientValidationEnabled
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7632141.html
Copyright © 2011-2022 走看看