zoukankan      html  css  js  c++  java
  • 51nod 1770 数数字

    基准时间限制:1 秒 空间限制:262144 KB 分值: 20 难度:3级算法题
     收藏
     关注

    统计一下 aaa  aaa��������������na × b 的结果里面有多少个数字d,a,b,d均为一位数。

    样例解释:

    3333333333*3=9999999999,里面有10个9。

    Input
    多组测试数据。
    第一行有一个整数T,表示测试数据的数目。(1≤T≤5000)
    接下来有T行,每一行表示一组测试数据,有4个整数a,b,d,n。 (1≤a,b≤9,0≤d≤9,1≤n≤10^9)
    Output
    对于每一组数据,输出一个整数占一行,表示答案。
    Input示例
    2
    3 3 9 10
    3 3 0 10
    Output示例
    10
    0
    /*
    51nod 1770 数数字
    
    problem:
    给你a,b,d,n. 求n个a与b相乘后其中d的个数
    
    样例解释:3 3 9 10
    3333333333*3=9999999999,里面有10个9
    
    
    solve:
    如果两者相乘小于10,那么和d比较进行判断.
    否则进行统计,会发现相乘到某一位时,它的进位会一直不变. 即n个a与b相乘后中间有一串
    数字是连续的,只要求到这串连续的开始位置即可.
    8 7 2 5
    --> 62216
    hhh-2016/09/03 12:13:07
    */
    #pragma comment(linker,"/STACK:124000000,124000000")
    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <map>
    #define lson  i<<1
    #define rson  i<<1|1
    #define ll long long
    #define clr(a,b) memset(a,b,sizeof(a))
    #define scanfi(a) scanf("%d",&a)
    #define scanfs(a) scanf("%s",a)
    #define scanfl(a) scanf("%I64d",&a)
    #define scanfd(a) scanf("%lf",&a)
    #define key_val ch[ch[root][1]][0]
    #define eps 1e-7
    #define inf 0x3f3f3f3f3f3f3f3f
    using namespace std;
    const ll mod = 1e9+7;
    const int maxn = 20010;
    const double PI = acos(-1.0);
    int num[10];
    
    int main()
    {
        int T,a,b,d,n;
        scanfi(T);
        while(T--)
        {
            clr(num,0);
            scanfi(a),scanfi(b),scanfi(d),scanfi(n);
            if(a * b < 10)
            {
                if(d == a*b)
                {
                    printf("%d
    ",n);
                }
                else
                    printf("0
    ");
            }
            else
            {
                int preup = -1,up = 0;
                for(int i = 1; i <= n; i++)
                {
                    int leave = (a*b+up)%10;
                    up = (a*b+up)/10;
                    num[leave] ++ ;
                    if(up == preup)
                    {
                        num[leave] += (n - i);
                        num[up] ++ ;
                        break;
                    }
                    if(i == n)
                    {
                        num[up] ++ ;
                    }
                    preup = up;
                }
                printf("%d
    ",num[d]);
            }
        }
        return 0;
    }
    /*
    10
    8 7 2 5
    7 7 4 10
    5 2 1 1
    
    3
    8
    1
    */
    

      

  • 相关阅读:
    mongodb
    python中读取文件的read、readline、readlines方法区别
    uva 129 Krypton Factor
    hdu 4734
    hdu 5182 PM2.5
    hdu 5179 beautiful number
    hdu 5178 pairs
    hdu 5176 The Experience of Love
    hdu 5175 Misaki's Kiss again
    hdu 5174 Ferries Wheel
  • 原文地址:https://www.cnblogs.com/Przz/p/5836710.html
Copyright © 2011-2022 走看看