• E Easy problem


    链接:https://ac.nowcoder.com/acm/contest/338/E
    来源:牛客网

    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

    读懂题
    题意• 
    找一个数(<=1e18),包含a1,a2,…,ak且是x的倍数。(0<=ai<=9,x<=1e8)
    题解• 
    令N=1023456789000000001) N%x==0 , ans = N
    • 2) N%x!=0, ans = N+(x-N%x)
    • 那么显然对于x<=1e8, ans包含0到9且ans是x的倍
    
    
    
     
    #include <stdio.h>
    
    long long n = 123456789000000000LL;
    
    
    int main()
    {
        int T,k,t,r;
        char buf[111];
        scanf("%d",&T);
        getchar();
        while(fgets(buf,100,stdin))
        {
            sscanf(buf,"%d",&k);
            r = n % k;
            t = k - r;
            printf("%lld
    ",n+t);
        }
        return 0;
    }
    View Code
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <cfloat>
    #include <climits>
    #include <iostream>
    #include <string>
    #include <vector>
    #include <list>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <algorithm>
    #include <bitset>
    using namespace std;
    
    #define LL long long
    const int maxn = 20;
    int T;
    LL x, k, ans;
    int num[maxn];
    
    int main()
    {
    #ifdef Dmaxiya
        freopen("test.txt", "r", stdin);
    #endif // Dmaxiya
        ios::sync_with_stdio(false);
    
        scanf("%d", &T);
        while(T--)
        {
            ans = 987654321000000000LL;
            scanf("%lld%lld", &x, &k);
            for(int i = 0; i < k; ++i)
            {
                scanf("%d", &num[i]);
            }
            printf("%lld
    ", ans + (x - ans % x));
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    INFORMATION_SCHEMA.COLUMNS表的字段信息
    如何取得一个数据表的所有列名
    CASE 函数
    Js定制窗口
    获取当前数据库中的所有用户表
    Js让状态栏不显示链接地址
    RA病人关节残障与软骨破坏而非骨破坏相关
    抗阿达木单抗的抗体可能与阿达木单抗治疗过程中静脉和动脉血栓事件相关
    长期应用阿达木单抗时所产生的抗抗体会影响疗效
    多普勒超声预测抗TNFα治疗类风湿关节炎患者的有效性:一项前瞻性队列研究
  • 原文地址:https://www.cnblogs.com/DWVictor/p/10229997.html
Copyright © 2020-2023  润新知