链接: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的倍数。(<=ai<=,x<=1e8)
题解•
令N=
• ) N%x== , ans = N
• ) N%x!=, 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",n+t);
}
return 0;
}
#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\n", ans + (x - ans % x));
} return 0;
}

E Easy problem的更多相关文章

  1. UVA-11991 Easy Problem from Rujia Liu?

    Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...

  2. An easy problem

    An easy problem Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  3. UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  4. POJ 2826 An Easy Problem?!

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7837   Accepted: 1145 ...

  5. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  6. 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?

    UVa11991 Easy Problem from Rujia Liu?  思路:  构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...

  7. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. UVA 11991 Easy Problem from Rujia Liu?(vector map)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  9. 数据结构(主席树):HDU 4729 An Easy Problem for Elfness

    An Easy Problem for Elfness Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65535/65535 K (J ...

  10. HDOJ(HDU) 2132 An easy problem

    Problem Description We once did a lot of recursional problem . I think some of them is easy for you ...

随机推荐

  1. 洛谷 P2783 有机化学之神偶尔会做作弊(Tarjan,LCA)

    题目背景 LS中学化学竞赛组教练是一个酷爱炉石的人. 有一天他一边搓炉石一边监考,而你作为一个信息竞赛的大神也来凑热闹. 然而你的化竞基友却向你求助了. “第1354题怎么做”<--手语 他问道 ...

  2. django之模型类在视图中的应用

    一:模型类直接从把前端表单传入的值,进行存储. @csrf_exempt def regist(request): if request.method == 'POST': form = UserFo ...

  3. LeetCode--043--字符串相乘(java)

    给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式. 示例 1: 输入: num1 = "2", num ...

  4. 使用getchar和putchar输入输出单个字符

    getchar()和putchar()只能用于输入输出单个字符,而不能字符串. #include<iostream> using namespace std; int main(){ ch ...

  5. php实现进度条原理

    PHP实现进度条的原理: 模版替换,在页面设置一个标识,轮子自己的页面,不发请求给服务器,由服务器端获得进度,然后替换该页面标识,达到进度条效果. 页面代码: 1 2 3 4 5 6 7 8 9 10 ...

  6. [CF959D]Mahmoud and Ehab and another array construction task题解

    解法 非常暴力的模拟. 一开始吧\(1 -> 2 \times 10^6\)全部扔进一个set里,如果之前取得数都是与原数组相同的,那么lower_bound一下找到set中大于等于它的数,否则 ...

  7. HTML基础入门学习准备篇

    在学习前端的开始,让我们一起来了解什么是HTML5时代的大前端开发和全栈开发的定义 传统的前端:切图-标签和样式-实现效果 H5时代的前端: 一.需要各端的兼容开发 二.可以用于APP开发和移动站点的 ...

  8. python 文件读写操作打开模式

    ‘r’:只读.该文件必须已存在. ‘r+’:可读可写.该文件必须已存在,写为追加在文件内容末尾. ‘rb’:表示以二进制方式读取文件.该文件必须已存在. ‘w’:只写.打开即默认创建一个新文件,如果文 ...

  9. 解决webpack打包vue项目后,部署完成后,刷新页面页面404

    1.url不动式url完全不动,即你的页面怎么改变,怎么跳转url都不会改变.这种情况的原理 就是纯ajax拿到页面后替换原页面中的元素,刷新页面就是首页 2.带hash(#)式这种相对于第一种的话刷 ...

  10. 170814关于Cookie的知识点

    1.会话控制 Http协议   Http协议两个缺陷: 1.HTTP协议是纯文本的    2.HTTP协议是无状态的 服务器不能简单的通过HTTP协议来区分多次请求是否发自同一个用户    虽然通过H ...