51nod 1770 数数字

https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1770&judgeId=593202

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

扫描二维码关注公众号,回复: 2554606 查看本文章
对于每一组数据,输出一个整数占一行,表示答案。

Input示例

2
3 3 9 10
3 3 0 10

Output示例

10
0

试过好多大数,他基本只会在倒数第一个数和倒数第二个数还有最高位变化,剩下的都一样

#include<iostream>
#include<string.h>
#define ll long long
#define maxn 11+5
using namespace std;
ll a[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		memset(a,0,sizeof(a));
		ll x,y,m,num,flag=0;
		scanf("%lld%lld%lld%lld",&x,&y,&m,&num);
		if(x*y<10)
		{
			if(m==x*y)
			cout<<num<<endl;
			else
			cout<<0<<endl;
		}
		else 
		{
			int add=x*y/10;
			int pre=x*y%10;
			a[pre]++;
			num--;
			while(num)
			{
				int sum=(x*y+add)%10;
				add=(add+x*y)/10;
				if(a[sum])
				{
					a[sum]+=num;
					break; 
				}
				else
				a[sum]++;
				num--; 
			}
			a[add]++;
			cout<<a[m]<<endl; 
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41453511/article/details/81410384