--bestcoder

2024-08-27 22:58
文章标签 bestcoder

本文主要是介绍--bestcoder,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Untitled

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 774    Accepted Submission(s): 423


Problem Description
There is an integer  a and n integers b1,,bn. After selecting some numbers from b1,,bn in any order, say c1,,cr, we want to make sure that a mod c1 mod c2 mod mod cr=0 (i.e., a will become the remainder divided by ci each time, and at the end, we want a to become 0). Please determine the minimum value of r. If the goal cannot be achieved, print 1 instead.

 

Input
The first line contains one integer  T5, which represents the number of testcases. 

For each testcase, there are two lines:

1. The first line contains two integers n and a (1n20,1a106).

2. The second line contains n integers b1,,bn (1in,1bi106).

 

Output
Print  T answers in T lines.

 

Sample Input
2 2 9 2 7 2 9 6 7

 

Sample Output
2 -1

 

不知道为什么必须判断比他大的数啊,老是超时,判断了就不超时了。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int t ;
int n,a;
int x[25];
bool cmp(int a,int b){
return a >b;
}
int dfs(int u,int depth){
if(u == 0)return depth;
int minn  = n+1;
for(int i = depth;i<n;i++){
int z = u>=x[i]?dfs(u % x[i],depth+1):n+1;
if( z < minn)minn = z;
}
return minn;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&a);
for(int i = 0;i<n;i++){
scanf("%d",&x[i]);
}
sort(x,x+n,cmp);
int minn = n+1;
for(int i = 0;i<n;i++){
int z = a >= x[i]?dfs(a % x[i],1):n+1;
if( z < minn) minn = z;
}
printf("%d\n",minn == n+1?-1:minn);
}
}

  

 

这篇关于--bestcoder的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1113021

相关文章

BestCoder Round #62 (div.2)Clarke and five-pointed star(极角排序,判断五边形)

题目链接 题意:给你五个点,问这五个点是否可以组成正五边形(正五角星,等价于正五边形)。 解答:先极角排序,(让五个点按照顺时针或者逆时针的顺序)然后我们计算五条边是不是一样,然后在看对角线是不是都一样。 #include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<set>#includ

BestCoder Round #62 (div.2)Clarke and food (简单贪心)

题目链接 题意:有个背包容量是V,现在有n个物品,每个物品有一个体积,问背包最多能装多少个。 解法:先排序,从小到大选。 #include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<set>#include<map>#include<string>#include<cstring>

BestCoder Round #42(3/4)

http://acm.hdu.edu.cn/showproblem.php?pid=5232 Shaking hands Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 169    Accepted Submission(s):

BestCoder Round #47 ($) HDU 5280 Senior\'s Array

http://acm.hdu.edu.cn/showproblem.php?pid=5280 考少年——报考杭州电子科技大学计算机学院  Senior's ArrayTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 244

BestCoder #47 10011002

【比赛链接】clikc here~~ ps:真是wuyu~~做了两小时,A出两道题,最后因为没加longlong全部被别人hack掉!,最后居然不知道hack别人不成功也会掉分,还一个劲的hack 别人的代码,昨天真是个悲催的比赛,~~~~(>_<)~~~~,下面弱弱献上代码~~ 1002比1001还简单~~ 1002  Senior's Gun /*BestCoder Round

BestCoder Round #20 解题报告 A.B.C.

A题:who is the best? 题目地址:HDU 5123 水题。 哈希,然后枚举找最大的,从小的开始找。 代码如下: #include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.

bestcoder 1002 Taking Bus

1002 Taking Bus简单的分类讨论,设s,x,y分别表示公交的始发站,起点和终点。大概有这样几种情况:1. s≤x<y, 2. x<s<y,3. x<y≤s, 4. s≤y<x, 5. y<s<x, 6. y<x≤s分别写出公式即可。答案应该会超过int,注意要用long long。/************************************************ Aut

BestCoder Round #61 (div.2)

比赛的时候过了两道,第三道超时20分钟过得 A题简单,我用了17分钟才写出来,看了界面熊大大的status,四分钟,直接把我吓傻,看了他的代码才知道,与大大之间的差距有多大: #include <iostream>#include <cstdio>#include <cmath>#include <cstring>#define LL long long#define pir pir

BestCoder Round #45

又把自己给坑了,,,,这样做下去太没意思了,要么好好干下去,要么趁早走人 A题水 B题,开始想了半天硬是没想出来,然后开始hack之后才写完算法,提交WA。想了半天感觉哪里都是对的,,,,,其实是自己太垃圾,简单的地方都能写错。 #include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#defin

BestCoder Round #43

水了两道题,而且有一道还被hack了。。。 A题不说 B题 刚看到题目我愣了半天,后来才想明白如果先对所有数取模,那么任意两个数的和一定在0到2q之间,准确的说,是在0到2Q-2之间,而且它们对Q的模存在两个极大值点,于是我的第一版写的是从小到大遍历,先与最后一个相加获得第二个极大值点,再二分小于Q的最大值,交上去第一次RE,当时没有仔细检查,直接数组开大十倍又交了遍Ac。然后就被HACK,