湖南大学第十四届ACM程序设计大赛 E Easy problem

链接:https://ac.nowcoder.com/acm/contest/338/E
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
Special Judge, 64bit IO Format: %lld

题目描述

Zghh likes number, but he doesn't like writing problem description. So he will just give you a problem instead of telling a long story for it.
Now given a positive integer x and k digits a1,a2,...,ak, can you find a positive integer y such that y is the multiple of x and in decimal representation y contains all digits of a1,a2,...,ak.

输入描述:

The first line contains an integer T (1<=T<=10000) which is the number of test case.The following T lines each line is a test case, start with two integer x (1<=x<=1e8) and k (1<=k<=10), k integer a1,a2,..,ak (0<=ai<=9 for i=1..k and ai!=aj for i!=j) is following.

输出描述:

For each test case output your answer y. Your answer should be a positive integer without leading zero and should be no more than 1e18. Every answer that satisfy the conditions descripted above will be accepted.

示例1

输入

复制

3
5 3 1 5 7
21 4 2 5 6 9
10 9 0 1 2 3 4 5 6 7 9

输出

复制

175
2592576
976543210

说明

175 is the multiple of 5 and contains 1,5,7

2592576 is the multiple of 21 and contains 2,5,6,9

976543210 is the multiple of 10 and contains 0,1,2,3,4,5,6,7,9

备注:

Constraint of data

1<=T<=10000

1<=x<=1e8

1<=k<=10

0<=ai<=9,for i=1..k

ai!=aj for i!=j

your answer y should satisfy y <= 1e18

题目大意:

ZGHH喜欢数字,但他不喜欢写问题描述。所以他只会给你一个问题,而不是长话短说。
现在给一个正整数x和k的数字a1,a2,…,a k,你能找到一个正整数y,这样y是x的倍数,在十进制表示中,y包含a1,a2,…,a k的所有数字。
第一行包含一个整数t(1<=t<=10000),它是测试用例的数目。下面的每行t是一个测试用例,从两个整数x(1<=x<=1e8)和k(1<=k<=10)、k整数a1、a2、、a k(0<=a i<=9,对于i=1..k和a i!AJ为我!=j)如下。
对于每个测试用例,输出您的答案Y。您的答案应该是不带前导零的正整数,并且不应超过1E18。所有符合上述条件的答案将被接受。

175是5的倍数,包含1,5,7

2592576是21的倍数,包含2,5,6,9

976543210是10的倍数,包含0、1、2、3、4、5、6、7、9

分析:

找一个数(<=1e18),包含a1,a2,...ak且是x的倍数。(0<=ai<=9,x<=1e8)

仔细读题会发现题目说所有符合上述条件的答案将被接受。即判题机对程序的结果检测时只要有一组符合即可,我们可以利用这个特点设定一个通用数n=1234567890,这个数包含ak中的所有个位数。再看x,题目限定(1<=x<=1e8),那么当n%x==0符合条件时n还是n。当n%x!=0时,要对n进行加工n=n+(x-n%x)以便能够让n被x整除,但(1<=x<=1e8)为了不破坏原数据,将n扩大1e8,因为1<=(x-n%x)<=1e8,将待补数放放到1234567890的后面。故初始定义n=123456789000000000。很巧的是这个数也正好在long long 范围内(比赛时看这个题提交正确的很少,以为是难题,后来才发现理解后这道题真的是easy problem)

#include<iostream>
using namespace std;
int main()
{
	long long n=123456789000000000;//定义初始数据
	int m,x,k,a[100];
	cin>>m;
	while(m--)
	{
		cin>>x>>k;
		for(int i=1;i<=k;i++)//感觉定义初始数据后,输入这些数据似乎并没什么用
			cin>>a[k];
		cout<<n+(x-n%x)<<endl;//对于取模不为0的要补充使其能够被x整除
	}
} 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值