题目链接: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. 转载: scikit-learn学习之回归分析

    版权声明:<—— 本文为作者呕心沥血打造,若要转载,请注明出处@http://blog.csdn.net/gamer_gyt <—— 目录(?)[+] ================== ...

  2. mongodb 最佳实践

    MongoDB功能预览:http://pan.baidu.com/s/1k2UfW MongoDB在赶集网的应用:http://pan.baidu.com/s/1bngxgLp MongoDB在京东的 ...

  3. java.sql.SQLException: Io 异常: Connection reset

    当数据库连接池中的连接被创建而长时间不使用的情况下,该连接会自动回收并失效,但客户端并不知道,在进行数据库操作时仍然使用的是无效的数据库连接,这样,就导致客户端程序报“ java.sql.SQLExc ...

  4. [MVC] 深入浅出Spring MVC

    [MVC] 深入浅出Spring MVC 转:http://4925054.blog.51cto.com/4915054/1176855 Spring MVC主要包括以下要点: 1:由Dispatch ...

  5. shopex后台上传模板漏洞

    看到有人找这个拿SHELL的方法.就本地搭建试了下.很简单的. 首先是WIN下.需要WIN主机IIS解析漏洞. 进入后台.点页面管理.点模板列表.默认模板是紫气东来(ShopEx4.8).点编辑模板. ...

  6. jQuery图片无缝滚动JS代码ul/li结构

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. POJ #2479 - Maximum sum

    Hi, I'm back. This is a realy classic DP problem to code. 1. You have to be crystal clear about what ...

  8. json换行符的处理

    JS端的: var s = JSON.stringify(str); var ss = s.replace(/\\n/g, "\\n") .replace(/\\'/g, &quo ...

  9. How to install Wordpress 4.0 on CentOS 7.0

    This document describes how to install and configure Wordpress 4.0 on CentOS 7.0. WordPress started ...

  10. c++中ifstream读文件的问题(关于eof())

    今天帮别人找BUG,是一段关于c++读写文件的问题,使用的是ifstream与outstream类,关于ofstream与ifstream的用法,此处不再獒述,见代码: #include<ios ...