51nod 1770 数数字

1770 数数字

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

 收藏

 关注

统计一下 aaa ? aaan个a × 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",n);
            }
            else
                printf("0\n");
        }
        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\n",num[d]);
        }
    }
    return 0;
}
/*
10
8 7 2 5
7 7 4 10
5 2 1 1

3
8
1
*/

  

时间: 2024-08-13 20:47:30

51nod 1770 数数字的相关文章

ACM学习历程—51NOD 1770数数字(循环节)

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1770 这是这次BSG白山极客挑战赛的A题.由于数字全部相同,乘上b必然会有循环节,于是模拟乘法,记录数据,出现循环就退出即可. 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring>

1770 数数字

1770 数数字 基准时间限制:1 秒 空间限制:262144 KB 统计一下由数字a组成的n位数与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 对于每一组数据,输出一个整数占一行,表示答案. Inp

51nod 数数字(水题)

题目链接: 数数字 基准时间限制:1 秒 空间限制:262144 KB 统计一下 aaa ? aaa n个a × 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 对于每一组数据,输出一个整数占一行

[2016-05-09][51nod][1002 数塔取数问题]

时间:2016-05-09 19:25:06 星期一 题目编号:[2016-05-09][51nod][1002 数塔取数问题] 题目大意: 一个高度为N的由正整数组成的三角形,从上走到下,求经过的数字和的最大值.每次只能走到下一层相邻的数上,例如从第3层的6向下走,只能走到第4层的2或9上. 分析:动态规划 dp[i][j] 表示到 dp[i][j]时的最大值 dp[i][j] = max(dp[i-1][j],dp[i - 1][j - 1]) + a[i][j]; ans = max(dp

java语言将任意一个十进制数数字转换为二进制形式,并输出转换后的结果

1 package com.llh.demo; 2 3 import java.util.Scanner; 4 5 /** 6 * 7 * @author llh 8 * 9 */ 10 public class Test { 11 /* 12 * 将任意一个十进制数数字转换为二进制形式,并输出转换后的结果(使用数组存储) 13 */ 14 public static void main(String[] args) { 15 Scanner sc = new Scanner(System.in

九章算法面试题52 数数字

九章算法官网-原文网址 http://www.jiuzhang.com/problem/52/ 题目 数一数在0到n之间有多少个数字k(0<=k<=9).如n=12时,[0,1,2...,12]之间一共有5个1.分别包含在[1, 10, 11, 12]之中. 在线测试本题 http://lintcode.com/problem/digit-counts/ 解答 本题的解法要诀在于熟练的使用递归思路和预处理. 预处理: f[0] 代表了0-9中有多少个数字k.(肯定=1) f[1] 代表了00-

51Nod - 1385 凑数字

51Nod - 1385 如果是n位数,x1 x2 x3 ... xn 从1到n的所有数中位数n-1的数字一定含有 1111...11,2222...22,...,9999...99 对于0 考虑n位数1000...00 其中有n-1个0 那么n-1位数中0-9都应该有n-1个(ans += 10*(n-1)) 考虑第一位数x1需要1, 2, 3, ..., x1(ans += x1) 但是如果第一位数大于第二位数 比如21 这时2最多出现一次,以为最高位出现时, 它的下一位不能出现2, 但是如

数数字 (Digit Counting,ACM/ICPC Danang 2007,UVa 1225)

思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. 13 string=12345678910111213 carr[1]++.carr[2]++.carr[3]++....carr[1]++.carr[1]++.carr[1]++.carr[2]++.carr[1]++.carr[3]++ AC Code: import java.util.Sc

LeetCode Count and Say 数数字

1 class Solution { 2 public: 3 string countAndSay(int n) { 4 if(n==1) return "1"; 5 string str0="",str1="1"; 6 int i,t,count; 7 char c='*'; 8 for(i=0;i<n-1;i++){ //一共要数n-1次,假如n=2,那么只要数str1这一次就行了 9 count=1; 10 if(i%2!=0){ /