题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3

题目大意:给你a,b两个数,问当b由约数1到100组成时,a能否由其它约数也在1到100的组成

就是dfs先枚举b的乘积组合,再看a有没有组合能够乘出来。。

代码:

 #include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define PB push_back
#define MP make_pair
#define SZ size()
#define CL clear()
#define AA first
#define BB second
#define EPS 1e-8
#define ZERO(x) memset((x),0,sizeof(x))
const int INF = ~0U>>;
const double PI = acos(-1.0); int a,b;
VI aa,bb;
bool vis[];
bool ok;
bool cansmall; bool dfsa(int cur,int now=){
bool res = false;
if(now==a){
return true;
}
if( now>a ) return false;
if( cur<aa.SZ ) res = res || dfsa(cur+,now);
if( cur<aa.SZ&&!vis[aa[cur]] ){
vis[aa[cur]] = true;
res = res||dfsa(cur+,now*aa[cur]);
vis[aa[cur]] = false;
}
return res;
} void dfsb(int cur,int now=){
// printf("now=%d\n",now);
if( ok ) return;
if(now==b){
cansmall = true;
bool flag = dfsa();
if( flag ){
ok = true;
}
return;
}
if( now>a ) return;
if( cur<bb.SZ ) dfsb(cur+,now);
if( cur<bb.SZ&&!vis[bb[cur]] ){
vis[bb[cur]] = ;
dfsb(cur+,now*bb[cur]);
vis[bb[cur]] = ;
}
} int main(){
while(scanf("%d%d",&a,&b)!=EOF){
if(a<b) swap(a,b);
aa.clear();
bb.clear();
for(int i=;i<=;i++){
if( a%i== ) aa.PB(i);
if( b%i== ) bb.PB(i);
} ZERO(vis); ok = cansmall = false; dfsb(); if( ok||!cansmall ) {
printf("%d\n",a);
} else {
printf("%d\n",b);
}
}
return ;
}

[ZOJ 1003] Crashing Balloon (dfs搜索)的更多相关文章

  1. ZOJ 1003 Crashing Balloon

    #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...

  2. [ZJU 1003] Crashing Balloon

    ZOJ Problem Set - 1003 Crashing Balloon Time Limit: 2 Seconds      Memory Limit: 65536 KB On every J ...

  3. ZJU-1003 Crashing Balloon dfs,

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题意(难以描述):A,B两个人从1~100选数乘起来比谁的大(不能选重复的或者 ...

  4. [ZOJ 1008]Gnome Tetravex (dfs搜索 + 小优化)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1008 题目大意:给你n*n的矩阵,每个格子里有4个三角形,分别是 ...

  5. 1003 Crashing Balloon

    考察DFS的应用,判断两个数的因子. #include <stdio.h> int f1,f2; void DFS(int m,int n,int k){ ){ f2=; ) f1=; } ...

  6. 【ZOJ1003】Crashing Balloon(DFS)

    Crashing Balloon Time Limit: 2 Seconds      Memory Limit: 65536 KB On every June 1st, the Children's ...

  7. [ZOJ 1011] NTA (dfs搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1011 题目大意:在一棵树上,给你起始状态,问你能否到达终止状态. ...

  8. 【Acm】算法之美—Crashing Balloon

    题目概述:Crashing Balloon On every  June 1st, the Children's Day, there will be a game named "crash ...

  9. ZOJ1003 Crashing Balloon

    Crashing Balloon Time Limit: 2 Seconds      Memory Limit: 65536 KB On every June 1st, the Children's ...

随机推荐

  1. MySQL 加锁处理分析 转

    MySQL 加锁处理分析  转 http://hedengcheng.com/?p=771 十二 13th, 2013 发表评论 | Trackback   1    背景    1 1.1    M ...

  2. RMAN备份与恢复之DataBase

    1   准备 [oracle@TEST144239 /]$ sqlplus /nolog SQL Production :: Copyright (c) , , Oracle. All rights ...

  3. [mysql] mysql表名忽略大小写

    首先查看mysql是否区分大小写: 今天郁闷死了,在LINUX下调一个程序老说找不到表,但是我明明是建了表的,在MYSQL的命令行下也可以查到,为什么程序就找不到表呢? 后来请教了一个老师才搞定,原来 ...

  4. Angular学习(6)- 数组双向梆定+filter+directive

    示例: <!DOCTYPE html> <html ng-app="MyApp"> <head> <title>Study 6< ...

  5. C++ Socket编程步骤 【转】

    sockets(套接字)编程有三种,流式套接字(SOCK_STREAM),数据报套接字(SOCK_DGRAM),原始套接字(SOCK_RAW):基于TCP的socket编程是采用的流式套接字. 服务器 ...

  6. c# .net sha256 16进制 64位 签名

    public static string GetSHA256hash(string input, string _input_charset) { byte[] clearBytes = Encodi ...

  7. CentOS 7.0 安装中文输入法

    这是个蛋疼的问题 1.Applications -- System Tools -- Setting -- Regin & Language 2.input source -- + -- mo ...

  8. Python函数,参数,变量

    func1.py def sayHello(): print ('hello world') sayHello() func_parm.py def printMax(a,b): if a>b: ...

  9. 怎样进行Android UI元素设计

    Android UI元素里面包含了许多的内容,比如:该平台由操作系统.中间件.用户界面和应用软件组成,一个应用程序要想受用户喜爱,那么UI可不能差. Android为相似的编程名词引入了一些新的术语, ...

  10. SpringMVC控制器设值原理分析(ModelAndView的值通过HttpServletRequest直接取到的原因)

    @RequestMapping("/userlist.do") public String getUserList(Model model){ HttpServletRequest ...