[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 ...
随机推荐
- PCA的数学原理
PCA(Principal Component Analysis)是一种常用的数据分析方法.PCA通过线性变换将原始数据变换为一组各维度线性无关的表示,可用于提取数据的主要特征分量,常用于高维 数据的 ...
- maven项目依赖小试牛刀
1.先建立空的wbh-parent,留下pom.xml;将项目中用的jar包依赖全放进去: 2.建立core项目,当然全是maven的,这个建好后,是用来让其他项目引用的,所以必须用maven ins ...
- C# MDI 子窗体被父窗体控件挡住
using System.Runtime.InteropServices; [DllImport("user32")] public static extern int SetPa ...
- 获取网页URL地址及参数等的两种方法(js和C#)
转:获取网页URL地址及参数等的两种方法(js和C#) 一 js 先看一个示例 用javascript获取url网址信息 <script type="text/javascript&q ...
- 71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", ...
- mssql查询某个值存在某个表里的哪个字段的值里面
第一步:创建 查询某个值存在某个表里的哪个字段的值里面 的存储过程 create proc spFind_Column_In_DB ( @type int,--类型:1为文字类型.2为数值类型 )-- ...
- Storm的数据处理编程单元:Bolt 学习整理
Bolt是Topology中的数据处理的单元,也是Storm针对处理过程的编程单元.Topology中所有的处理都是在这些Bolt中完成的,编程人员可以实现自定义的处理过程,例如,过滤.函数.聚集.连 ...
- Flink on Yarn运行机制
从图中可以看出,Yarn的客户端需要获取hadoop的配置信息,连接Yarn的ResourceManager.所以要有设置有 YARN_CONF_DIR或者HADOOP_CONF_DIR或者HADOO ...
- OAF_架构MVC系列3 - View的概述(概念)
2014-06-18 Created By BaoXinjian
- python 爬虫抓取心得
quanwei9958 转自 python 爬虫抓取心得分享 urllib.quote('要编码的字符串') 如果你要在url请求里面放入中文,对相应的中文进行编码的话,可以用: urllib.quo ...