Untitled

Accepts: 504
Submissions: 1542
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description

There is an integer aaa and nnn integers b1,…,bnb_1, \ldots, b_nb​1​​,…,b​n​​. After selecting some numbers from b1,…,bnb_1, \ldots, b_nb​1​​,…,b​n​​ in any order, say c1,…,crc_1, \ldots, c_rc​1​​,…,c​r​​, we want to make sure that a mod c1 mod c2 mod… mod cr=0a \ mod \ c_1 \ mod \ c_2 \ mod \ldots \ mod \ c_r = 0a mod c​1​​ mod c​2​​ mod… mod c​r​​=0 (i.e., aaa will become the remainder divided by cic_ic​i​​ each time, and at the end, we want aaa to become 000). Please determine the minimum value of rrr. If the goal cannot be achieved, print −1-1−1 instead.

Input

The first line contains one integer T≤5T \leq 5T≤5, which represents the number of testcases.

For each testcase, there are two lines:

  1. The first line contains two integers nnn and aaa (1≤n≤20,1≤a≤1061 \leq n \leq 20, 1 \leq a \leq 10^61≤n≤20,1≤a≤10​6​​).

  2. The second line contains nnn integers b1,…,bnb_1, \ldots, b_nb​1​​,…,b​n​​ (∀1≤i≤n,1≤bi≤106\forall 1\leq i \leq n, 1 \leq b_i \leq 10^6∀1≤i≤n,1≤b​i​​≤10​6​​).

Output

Print TTT answers in TTT lines.

Sample Input
2
2 9
2 7
2 9
6 7
Sample Output
2
-1 运用二进制的思想,去枚举每种可能的情况,然后算下最小的。当然,先把比 a 大的数筛掉
#include <iostream>
#include <algorithm>
using namespace std; int main()
{
int T;
cin >> T;
int n, a, b[], i, cnt;
while(T--) {
int Min = ;
bool tag = false;
cin >>n >> a;
for(int i = ; i < n; ++i)
cin >> b[i];
sort(b, b+n);
for(i = n-; i >= ; --i) {
if(a >= b[i])
break;
}
if(i == ) {
if(a % b[] == )
cout << << endl;
else
cout << - << endl;
} else {
for(int j = ; j < ( << (i+)); ++j) {
int tmp = a;
cnt = ;
for(int k = i; k >= ; --k) {
if(( << k) & j) {
tmp %= b[k];
cnt++;
//cout << j << " " <<tmp << " " << b[k] << " "<<cnt << endl;;
}
}
if(tmp == ) {
Min = min(Min, cnt);
tag = true;
}
}
if(tag)
cout << Min << endl;
else
cout << - << endl;
}
}
return ;
}

BestCoder#49的更多相关文章

  1. BestCoder #49 Untitled HDU 5339

    BestCoder #49 Untitled  HDU 5339 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5339 本题採用深搜, 数据量小,先做 ...

  2. Manacher BestCoder Round #49 ($) 1002 Three Palindromes

    题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...

  3. BestCoder Round #49

    呵呵哒,1001的dfs返回值写错,wa了两发就没分了,1002显然是PAM可是我没学过啊!!!压位暴力可不可以...看看范围貌似不行,弃疗...1003根本不会做,1004想了想lcc发现不可做,那 ...

  4. DFS BestCoder Round #49 ($) 1001 Untitled

    题目传送门 /* DFS:从大到小取模,因为对比自己大的数取模没意义,可以剪枝.但是我从小到大也过了,可能没啥大数据 */ /************************************* ...

  5. CodeForce Round#49 untitled (Hdu 5339)

    Untitled Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  6. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  7. Bestcoder#5 1002

    Bestcoder#5 1002 Poor MitsuiTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  8. 49. 3种方法实现复杂链表的复制[clone of complex linked list]

    [本文链接] http://www.cnblogs.com/hellogiser/p/clone-of-complex-linked-list.html [题目] 有一个复杂链表,其结点除了有一个ne ...

  9. BestCoder Round #80 1002

    HDU 5666 Segment 题意:给你条斜率为-1,常数项为q(q为质数)的直线,连接原点与直线上整数格点,问你在有多少个格点在形成的无数个三角形内,而不在线段上,结果对P取模. 思路:best ...

随机推荐

  1. PHP与MYSQL事务处理

    /*MYSQL的事务处理主要有两种方法.1.用begin,rollback,commit来实现begin 开始一个事务rollback 事务回滚commit 事务确认2.直接用set来改变mysql的 ...

  2. C++ 与OpenCV 学习笔记

    联合体:当多个数据需要共享内存或者多个数据每次只取其一时,可以利用联合体(union) 1. 联合体是一种结构: 2. 他的所有成员相对于基地址的偏移量均为0: 3. 此结构空间要大到足够容纳最&qu ...

  3. BMP图像差分/比较

    #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char ...

  4. EndNote(一)之基本介绍

    作为一个经常看文献的人,发现看了很多文献,但是之后需要再找某一篇文献的时候,却无法找到文献在哪里了.混乱的文献管理方式,浪费了很多时间在翻阅自己已经看过的文献之中.这是一件很头痛的事情,才想起借助软件 ...

  5. Redis启动多端口、运行多实例

    默认Redis程序安装在/usr/local/redis目录下: 配置文件:/usr/local/redis/redis.conf,该配置文件中配置的端口为默认端口:6379: Redis的启动命令路 ...

  6. JNDI

    这两天研究了一下 context.lookup("java:comp/env/XXX")和直接context.lookup("XXX")的区别 网上关于这两个的 ...

  7. 循环冗余码crc

    待编码的有效信息组多项式:M(x) 生成多项式(产生校验码的多项式):G(x) 余数多项式:R(x) 商:Q(x) 生成多项式是四次的,所以某个多项式除以生成多项式的余式肯定是三次的,所以要加四位00 ...

  8. PHP修改表格(增删改)

    要求: 1.熟练shi用  post 和  get  传值        2. php嵌套在HTML中        3.熟练:if 语句(其他语句)的使用 --------------------- ...

  9. vue笔记

    安装vue脚手架工具 sudo cnpm install -g vue-cli

  10. AE+C# 版本更新问题 命名空间“ESRI”中不存在类型或命名空间名称“Arcgis”(是缺少程序集引用吗?)

    解决办法: 1 引用 将下图中解决方案->引用中带感叹号的已用移除,然后添加新的.因为不同版本用的.dll不同,因此需要删除,然后重新加载. 如果是系统库文件, 直接在.NET下头添加,如果是自 ...