湖南大学第十四届ACM程序设计新生杯 E.Easy Problem

E.Easy Problem

Description:

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.

Input:

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.

Output:

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.

Sample Input:

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

Sample Output:

175
2592576
976543210

题意:

多组数据,每组数据给出一个数x,然后k个0~9的数,现在要你求出一个数y,满足y%x=0并且y包含这k个数。

题解:

比赛的时候想了半天都没有想到啊...后来看别人的代码恍然大悟。

注意这里的数据范围,x只有1e8,然后0~9一共10个数,所以我们可以选取一个大数比如1234567890*1e8,可以将这个作为答案进行待定。

因为要求能够整除,所以我们用这个大数(假定为n)n%x,令r=n%x,那么易知r是小于1e8的,我们现在用n加上x-r那么就可以同时满足题目中的条件了。

这里如果用减的话可能会因为借位而对1234567890进行改变,用加就不用担心这个问题出现了。

感觉思路特别巧妙,主要还是对数据范围的细心观察。

代码如下:

#include <bits/stdc++.h>
typedef long long ll;
ll n = 123456789000000000;
int main(){
    ll T,k,t,r;
    ll x;
    scanf("%lld",&T);
    while(T--){
        scanf("%lld %lld",&x,&k);
        for(int i=1;i<=k;i++){
            int tmp;
            scanf("%d",&tmp);
        }
        r = n % x;
        t = x - r;
        printf("%lld\n",n+t);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/heyuhhh/p/10230003.html

时间: 2024-07-29 04:23:08

湖南大学第十四届ACM程序设计新生杯 E.Easy Problem的相关文章

湖南大学第十四届ACM程序设计新生杯 Dandan&#39;s lunch

Dandan's lunch Description: As everyone knows, there are now n people participating in the competition. It was finally lunch time after 3 hours of the competition. Everyone brought a triangular bread. When they were going to eat bread, some people fo

浙江省第十四届大学生程序设计竞赛总结

恐怖故事,开场,我从后往前读题. 看到$M$,我感觉上好像会做,但不知道是不是最优策略.跳过. 看到$L$,我感觉上好像是找规律,算了几个样例,发现可能是那个规律,没仔细思考.跳过. 这时候,$xiang578$偷偷摸摸$AC$了一题. $Occult$看了$E$题.可以写,先跳过. 紧接着,有人过题,$xiang578$看题,$Occult$把前四题剩下的三题都$AC$了. 前四题貌似是简单题,都是$1A$,最终全场$160+$队伍过了四个及以上题目. 我在一旁划水,期间看了$I$题和$F$题

湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e18) guys standing in a row, because the boys had some strange character,The first time to Liao them will not be successful, but the second time will be su

湖南大学ACM程序设计新生杯大赛(同步赛)B - Build

题目描述 In country  A, some roads are to be built to connect the cities.However, due to limited funds, only some roads can be built.That is to say,if the limit is 100$, only roads whose cost are no more than 100$ can be built. Now give you n cities, m r

湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks

题目描述 BSD is a lazy boy. He doesn't want to wash his socks, but he will have a data structure called 'socks heap'.By maintaining this structure, he can quickly pick out two of the most smelless socks from millions of socks everyday. As one of his good

湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2

题目描述 Once there was a pig, which was very fond of treasure hunting. One day, when it woke up, it found itself in a strange land of treasure. As for how to come in, or how to go out, no ways to know. Sad. The good news is, it was lucky that it got the

HDU 6467 简单数学题 【递推公式 &amp;&amp; O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 308    Accepted Submission(s): 150 Problem Description 已知 F(n)=∑i=1n(i×∑j=inCij) 求 F(n) m

第十四届华中科技大学程序设计竞赛决赛同步赛

第十四届华中科技大学程序设计竞赛决赛同步赛 A Beauty of Trees 思维,带权并查集 题意: 长度为 n 的序列,没告诉你具体数是多少.只给出 m 个查询,表示区间 [l,r] 的异或和为 k .但是第 i 个查询如果和前面的查询有矛盾,那就是错误的.输出所有的错误查询. tags: 对于一个查询,我们知道 sum[r] ^ sum[l-1] = k . 建成图就是 r -> (l-1) ,但要快速地求出异或值,就要用带权并查集处理.如有 sum[r]^sum[l-1]=k,即 r

没有什么不可能—记山东省第六届ACM程序设计竞赛(退役总结帖)

大一下学期,第一次听说了ACM这个词,当时每周六也开设了培训课,但我好像一次也没有去过,当时对这个词并没有什么太大的印象.后来学院里引进了自己的OJ,那时候我连基本的输入输出格式都不懂,当经历了一堆的WA,TLE之后突然换来的一个AC竟带来了莫名的喜悦.后来学院举办了第一届ACM程序设计竞赛,我报名参加了新秀赛和团队赛.三个小时的新秀赛,当时貌似做出了三道,意外的拿到了一等奖,这也成为了我大学生活的一个重要转折点.四个小时的团队赛,做得很艰难,各种不会,最后只做出了一道,排在三等奖的末尾.比赛之