码迷,mamicode.com
首页 > 其他好文 > 详细

BC #49 1001 Untitled

时间:2015-08-30 19:30:41      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

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 -11 instead.

Input

The first line contains one integer T \leq 5T5, 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^61n20,1a10?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^61in,1b?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 }
View Code

 

BC #49 1001 Untitled

标签:

原文地址:http://www.cnblogs.com/cyd308/p/4771339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!