[ZOJ 1003] Crashing Balloon (dfs搜索)
题目链接: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搜索)的更多相关文章
- ZOJ 1003 Crashing Balloon
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...
- [ZJU 1003] Crashing Balloon
ZOJ Problem Set - 1003 Crashing Balloon Time Limit: 2 Seconds Memory Limit: 65536 KB On every J ...
- ZJU-1003 Crashing Balloon dfs,
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题意(难以描述):A,B两个人从1~100选数乘起来比谁的大(不能选重复的或者 ...
- [ZOJ 1008]Gnome Tetravex (dfs搜索 + 小优化)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1008 题目大意:给你n*n的矩阵,每个格子里有4个三角形,分别是 ...
- 1003 Crashing Balloon
考察DFS的应用,判断两个数的因子. #include <stdio.h> int f1,f2; void DFS(int m,int n,int k){ ){ f2=; ) f1=; } ...
- 【ZOJ1003】Crashing Balloon(DFS)
Crashing Balloon Time Limit: 2 Seconds Memory Limit: 65536 KB On every June 1st, the Children's ...
- [ZOJ 1011] NTA (dfs搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1011 题目大意:在一棵树上,给你起始状态,问你能否到达终止状态. ...
- 【Acm】算法之美—Crashing Balloon
题目概述:Crashing Balloon On every June 1st, the Children's Day, there will be a game named "crash ...
- ZOJ1003 Crashing Balloon
Crashing Balloon Time Limit: 2 Seconds Memory Limit: 65536 KB On every June 1st, the Children's ...
随机推荐
- IntelliJ IDEA中配置reportNG
找了好多资料,各种设置都是eclipse上面的.后来发现原来就在Run->Edit Configurations->TestNG->Configuration->Listenn ...
- web前端面试2
百度另外一部门面试 1.前端html5新特性 2.数组常用函数 3.前后台json树形结构遍历,对算法的了解 4.css3背景属性设置为适合匹配模块的属性是什么 5.jquery插件的写法 6.研究过 ...
- Windows命令行查看文件的MD5
certutil -hashfile D:\apache-tomcat-7.0.68-windows-x64.zip MD5certutil -hashfile D:\apache-tomcat-7 ...
- SSH_框架整合5--验证用户名是否可用
SSH_框架整合5--验证用户名是否可用 1 emp-input.jsp中编写ajax验证用户名是否可用: <script type="text/javascript" SR ...
- SVN学习之svn命令行下的基本操作
http://huihai.iteye.com/blog/1985751 上一节已经把svn安装完成,下来就用命令行做一些简单的操作. 1.当svn安装完成后,svn管理人员会在svn的root根目录 ...
- 详解 “Android UI”设计官方教程
我们曾经给大家一个<MeeGo移动终端设备开发UI设计基础教程>,同时很多朋友都在寻找Android UI开发的教程,我们从Android的官方开发者博客找了一份幻灯片,介绍了一些Andr ...
- 回到顶部缓动效果代码 --- tween动画函数库
function animateGoTop() { var top = $(document).scrollTop(); var end = 0; var dur = 500; var t = 0; ...
- 黄聪:360浏览器、Chrome调试(debugger)JS总是进入paused in debugger状态
在通过Chrome浏览器进行web前端开发时,我们会经常用到Chrome自带的debugger工具,但是经常按完快捷键(F12)后,页面会进入paused in debugger状态,需要点击右上角的 ...
- Objective-C语法汇总
1.方法前的加减号 Objective-C中是没有public与private的概念的,即可以认为全部都是public.减号表示的是一个函数.方法.消息的开始.加号则表示不需要创建一个类的实例,其他类 ...
- C和C++混合编程
extern "C"表示编译生成的内部符号名使用C约定.C++支持函数重载,而C不支持,两者的编译规则也不一样.函数被C++编译后在符号库中的名字与C语言的不 同.例如,假设某个函 ...