E Easy problem
链接:https://ac.nowcoder.com/acm/contest/338/E
来源:牛客网
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.
备注:
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的更多相关文章
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- An easy problem
An easy problem Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- 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, ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?
UVa11991 Easy Problem from Rujia Liu? 思路: 构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- 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, ...
- 数据结构(主席树):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 ...
- 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 ...
随机推荐
- 微信支付签名算法JavaScript版,参数名ASCII码从小到大排序;0,A,B,a,b;
// 支付md5加密获取sign paysignjs: function (jsonobj) { var signstr = this.obj2str(jsonobj) signstr = signs ...
- maven 提取jar包 依赖及打包排除
<properties> <project.targetDir>D:\jar</project.targetDir> <project.targetServe ...
- [python 学习] 使用 xml.etree.ElementTree 模块处理 XML
---恢复内容开始--- 导入数据(读文件和读字符串) 本地文件 country_data.xml <?xml version="1.0"?> <data> ...
- django之静态文件的设置
一:静态文件 Django中提供了一种解析的方式配置静态文件路径.静态文件可以放在项目根目录下,也可以放在应用的目录下,由于有些静态文件在项目中是通用的,所以推荐放在项目的根目录下,方便管理. 为了提 ...
- NIO之FileChannel操作示例
1. 写文件操作 /** * 写文件 */ public class FileChannelTest { public static void main(String[] args) throws I ...
- URL跳转漏洞
URL跳转原理: 由于越来越多的需要和其他第三方应用交互,以及在自身应用内部根据不同的逻辑将用户引向到不同的页面,譬如一个典型的登录接口就经常需要在认证成功之后将用户引导到登录之前的页面,整个过程中如 ...
- Ponds
Ponds Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Sub ...
- 微信小程序填坑之路其一:wx.request发送与服务端接受
一.序言 应公司要求要求,要用小程序开发一个信息录入系统.没办法只能听话来填坑. 先介绍一下环境:客户端——小程序:服务端——java:数据库——mysql:服务器——centos7 需求:客户端输入 ...
- SecondContract 接口类
package com.test.mvp.mvpdemo.mvp.v6; import com.test.mvp.mvpdemo.mvp.v6.basemvp.IBasePresenter;impor ...
- LintCode之最长单词
题目描述: 分析:先建一个数组s用来存储每个字符串的长度,然后遍历数组s得到最大的数max,这个数就是词典中的最长单词的长度,由于可能有多个长度相等的单词,所以要循环整个词典,当一个单词的长度等于ma ...