湖南大学第十四届ACM新生赛--E---Easy problem

Easy problem

TimeLimit:C/C++ 1S,JAVA:2S
MemoryLimit:C/C++ 32.000MB,JAVA:64.000MB

题目描述
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.

示例输入
3
5 3 1 5 7
21 4 2 5 6 9
10 8 0 1 2 3 4 5 6 7 9
输出
175
2592576
976543210

解:

题意为要找出一个数,既是x的倍数,同时又含有a1,a2……ak,这些数字,如果粗暴地来,按顺序依次检验x的倍数是否含有目标数字,肯定超时,需要改进思路。
而由于本题Special Judge可以有多个正确的解,我们只需要找一个很大很特殊的数,同时含有1,2,3,4,5,6,7,8,9,0中的所有数字,再根据x适当调整成他的倍数,而不影响数字的组成,就可以得到想要的“通解”

#include<bits/stdc++.h>
#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
	long long m,n,i,j,k,p,t,y,chang,ge;
	int a[11],x;
	scanf("%lld",&t);
	
	for(p=0;p<t;p++)
	{
		long long n=1023456789000000000;//取一个很大的n,同时含有1234567890,且
		在被调整后不影响数字组成。
		scanf("%d%lld",&x,&k);
		for(i=0;i<k;i++)
		{
			scanf("%lld",&a[i]);//做做样子输入就行,其实用不上 
		}
		printf("%lld\n",n+(x-n%x));//输出调整后的n
	}
 } 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值