BC #49 1001 Untitled

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 aa and nn integers b_1, \ldots, b_nb?1??,…,b?n??. After selecting some numbers from b_1, \ldots, b_nb?1??,…,b?n?? in any order, say c_1, \ldots, c_rc?1??,…,c?r??, we want to make sure that a \ 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., aa will become the remainder divided by c_ic?i?? each time, and at the end, we want aa to become 00). Please determine the minimum value of rr. If the goal cannot be achieved, print -1−1 instead.

Input

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

For each testcase, there are two lines:

  1. The first line contains two integers nn and aa (1 \leq n \leq 20, 1 \leq a \leq 10^61≤n≤20,1≤a≤10?6??).
  2. The second line contains nn integers b_1, \ldots, b_nb?1??,…,b?n?? (\forall 1\leq i \leq n, 1 \leq b_i \leq 10^6∀1≤i≤n,1≤b?i??≤10?6??).

Output

Print TT answers in TT lines.

Sample Input

2
2 9
2 7
2 9
6 7

Sample Output

2
-1

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5 char s[20005];
 6 int x[20005],y[20005],n,m;
 7
 8 int judge(int a,int b)
 9 {
10     int flg=1;
11     while(a<b)
12     {
13         if(s[a]!=s[b])
14         {
15             flg=0;
16             break;
17         }
18         a++,b--;
19     }
20     return flg;
21 }
22
23 int main()
24 {
25     int T;
26     int i,j;
27     scanf("%d",&T);
28     while(T--)
29     {
30         scanf("%s",s);
31         int l=strlen(s);
32         int oo=1;
33         for(i=1;i<l;i++)
34         {
35             if(s[i]!=s[i-1])
36             {
37                 oo=0;
38                 break;
39             }
40         }
41         if(oo==1)
42             printf("Yes\n");
43         else
44         {
45         n=0,m=0;
46         x[0]=0,y[0]=l-1;
47         for(i=1;i<=l-3;i++)
48         {
49             if(judge(0,i)==1)
50             {
51                 n++;
52                 x[n]=i;
53             }
54         }
55         for(i=l-2;i>=2;i--)
56         {
57             if(judge(i,l-1)==1)
58             {
59                 m++;
60                 y[m]=i;
61             }
62         }
63         int ans=0;
64         for(i=0;i<=n;i++)
65         {
66             if(ans==1)
67                 break;
68             for(j=0;j<=m;j++)
69             {
70                 if(y[j]-x[i]<=1)
71                     break;
72                 if(judge(x[i]+1,y[j]-1)==1)
73                 {
74                     ans=1;
75                     break;
76                 }
77             }
78         }
79
80         if(ans==1)
81             printf("Yes\n");
82         else
83             printf("No\n");
84         }
85     }
86     return 0;
87 }

时间: 2024-08-26 01:30:46

BC #49 1001 Untitled的相关文章

BestCoder Round #49 ($) 1001 Untitled

5339  Untitled 问题描述 有一个整数aa和nn个整数b_1, \ldots, b_nb?1??,-,b?n??.在这些数中选出若干个数并重新排列,得到c_1, \ldots, c_rc?1??,-,c?r??.我们想保证a \ mod \ c_1 \ mod \ c_2 \ mod \ldots \ mod \ c_r = 0a mod c?1?? mod c?2?? mod- mod c?r??=0.请你得出最小的rr,也就是最少要选择多少个数字.如果无解,请输出-1?1. 输入

HDU 4907 (杭电BC#3 1001)Task schedule(水)

题目地址:HDU 4907 水题...不多说..哈希后从后往前遍历一遍就行了. 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include<a

hdu 5364 (bc#50 1001) Distribution money

Distribution money Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 276    Accepted Submission(s): 163 Problem Description AFA want to distribution her money to somebody.She divide her money into

HDU 4883 (BC#2 1001题)TIANKENG’s restaurant(水)

题目地址:HDU 4883 唉..最近得了一种惯性..刚学了什么就碰到个类似的就想用刚学的算法...原来这题如此简单..当时真是想多了.... 只要在需要变化的点上设置一个值,是增多少还是减多少.然后当遍历过来的时候加上或减去这个值就行了... 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

BC round 49 A Untitled

本来是坐了两题的,结果第二题被黑了,两题的时候排名room第三,真是吓到我了,说实话这次真是认真做的,结 果还不错虽然只过了一题,貌似没几个人过两题,BC就是这么坑,老是出这么难的题,而且这两次我做的都是递归结出来的,还都是三次递归...好多人爆零,我还是一如既往的一道题,好像从来都是一道题...继续努力 认真做题,认真做题,认真做题(重要的事说三遍) 思路: 这道题我没有排序,直接递归的因为层数是递增的,所以可以优先找到层数最少的,每次对小于当前的数取余就ok啦,然后继续递归它的余数,直到为0

BC #50 1001 Distribution money

Distribution money Accepts: 713 Submissions: 1881 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description AFA want to distribution her money to somebody.She divide her money into n same parts.One who want

BC#53 1001 Rikka with Graph

Rikka with Graph Accepts: 353 Submissions: 1174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math

bc 一周年 1001 Souvenir (hdu 5310)

Souvenir Accepts: 901 Submissions: 2743 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 今天是BestCoder一周年纪念日. 比赛管理员Soda想要给每个参赛者准备一个纪念品. 商店里纪念品的单价是$p$元, 同时也可以花$q$元购买纪念品套装, 一个套装里有$m$个纪念品. 今天总共有$n$个参赛者, Soda想要知道最少需要

BestCoder Round #49

呵呵哒,1001的dfs返回值写错,wa了两发就没分了,1002显然是PAM可是我没学过啊!!!压位暴力可不可以...看看范围貌似不行,弃疗...1003根本不会做,1004想了想lcc发现不可做,那就是仙人掌分治,没写完囧... 最后Rating+69滚粗了... 官方题解: 1001 Untitled 对于一组可能的答案cc,如果先对一个觉小的c_ic?i??取模,再对一个较大的c_jc?j??取模,那么这个较大的c_jc?j??肯定是没有用的.因此最终的答案序列中的cc肯定是不增的.那么就