hdu 5339 Untitled【搜索】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5339
题意:一个整数a 和一个数组b。问你能否在b中取出r个元素排列组成c数组满足a%c1%c1%…..%cr == 0。输出最小的r,不能满足条件输出-1。
思路:b按从大到小排序,暴搜。
代码:
#include <stdio.h>
#include <ctime>
#include <math.h>
#include <limits.h>
#include <complex>
#include <string>
#include <functional>
#include <iterator>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <assert.h>
using namespace std;
int n, a, b[300],ans;
bool cmp11(int a, int b)
{
return a > b;
}
void dfs(int x,int num,int A)
{
if (x == 0)
{
ans = min(ans, A); return;
}
if (num == n) return;
//printf(" %d\n",x);
dfs(x % b[num + 1], num + 1, A + 1);
dfs(x, num + 1, A);
}
int main()
{
//printf("3 % 7");
int t;
scanf("%d",&t);
while (t--)
{
scanf("%d %d", &n, &a);
for (int i = 1; i <= n; i++)
scanf("%d", &b[i]);
sort(b + 1, b + 1 + n, cmp11);
ans = 500;
dfs(a, 0, 0);
if (ans == 500) ans = -1;
printf("%d\n", ans);
}
return 0;
}
hdu 5339 Untitled【搜索】的更多相关文章
- hdu 5339 Untitled
这题很明显是签到题,可我比赛时却没做出,赤裸裸的爆零了,真悲剧…… 看了题解后才知道直接暴搜就行,只是需要把它们从大到小排序后再搜,我当时就没想到...不想再多说了 一开始我直接枚举所有情况: #in ...
- HDU 5339 Untitled (暴力枚举)
题意:给定一个序列,要求从这个序列中挑出k个数字,使得n%a1%a2%a3....=0(顺序随你意).求k的最小值. 思路:排个序,从大的数开始模起,这是因为小的模完还能模大的么? 每个元素可以选,也 ...
- BestCoder #49 Untitled HDU 5339
BestCoder #49 Untitled HDU 5339 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5339 本题採用深搜, 数据量小,先做 ...
- CodeForce Round#49 untitled (Hdu 5339)
Untitled Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- hdu 5468(莫比乌斯+搜索)
hdu 5468 Puzzled Elena /*快速通道*/ Sample Input 5 1 2 1 3 2 4 2 5 6 2 3 4 5 Sample Output Case #1: ...
- HDU 4499.Cannon 搜索
Cannon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- HDU 1045 (DFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意:在不是X的地方放O,所有O在没有隔板情况下不能对视(横行和数列),问最多可以放多少个 ...
- HDU 1180 (BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1180 题目大意:迷宫中有一堆楼梯,楼梯横竖变化.这些楼梯在奇数时间会变成相反状态,通过楼梯会顺便到达 ...
- HDU 2531 (BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2531 题目大意: 你的身体占据多个点.每次移动全部的点,不能撞到障碍点,问撞到目标点块(多个点)的最 ...
随机推荐
- 数据结构算法——链表的各种操作,C++和Python
时隔已久,一直没更新博客,感觉很愧疚呀. 先贴上所有的代码.这个是用C++写的 #include "stdafx.h" //Author:Albert //Date: 2018.1 ...
- Android view相关与自定义View
一.关于view的机制的问答 1.gesturedetector和ontouchevent的区别 gesturedetector指的是手势检测器,根据动态手势的运动特性,提出了速率边沿检测算法来分割手 ...
- webform登陆界面样式丢失
本文摘抄自:http://blog.csdn.net/sssix/article/details/16945347 请阅读原文. Forms验证——登录界面样式实效? <authenticati ...
- 一个 Java 的 Socket 服务器和客户端通信的例子
一个 HelloWord 级别的 Java Socket 通信的例子.通讯过程: 先启动 Server 端,进入一个死循环以便一直监听某端口是否有连接请求.然后运行 Client 端,客户端发出连接请 ...
- CMake 使用笔记
记录 CMake 相关知识. Prelude:读文档一定要有耐心! 问题一 CLion: CMakeLists.txt 中 set(CMAKE_CXX_FLAGS -Wall) 不起作用 Soluti ...
- input聚焦时,滚动至可视区域
这里的代码来自vux,觉得vux处理得很好,在此记录一下. 当我们在手机上填表单的时候,我们会希望正在填的input或者textarea会自动滚动至可视区域,方便我们边填写边查看内容.以前我的做法是, ...
- URAL1960 Palindromes and Super Abilities
After solving seven problems on Timus Online Judge with a word “palindrome” in the problem name, Mis ...
- VIM使用技巧2
假如有以下程序片段: var foo = 1 var bar = 'a' var foobar = foo + bar 如果我们想在每行行尾加上分号, (1)使用$移动光标到行尾, (2)执行a;&l ...
- jquery 中的post和get方法同步问题
解决方法: 在需要同步的js代码前修改ajax的async属性. 有两种设置方法: 1: $.ajaxSettings.async = false; 2: $.ajaxSetup({ async : ...
- Cryptography I 学习笔记 --- 零碎
1. KDF(密钥推导函数,key derivation function),根据用户输入的一个初始密钥来生成一系列的后续密钥.可以使用PRF来生成 2. 可以用salt与slow hash func ...