传送门:点我

题意:给定n长度的序列,重排成后一个数是前一个数除以三,或者后一个数是前一个数乘二,要求输出这个序列。

思路:大力深搜,对每个数搜除3的和乘2的是否出现过,然后继续搜下去。如果有一个数搜能搜完整个序列,那就输出这个数开始的一整个序列。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
int ans = ,flag = ;
int n,k;
map<LL,int>ma;
LL b[];
void dfs(LL x){
if(ans == n - ){
flag = ;
for(int i = ; i <= ans; i++){
i == ans ?printf("%I64u\n",b[i]):printf("%I64u ",b[i]);
}
return;
}
if(x%==&&ma[x/] == ){
ans++;
b[ans] = x/;
dfs(x/);
}
if(ma[x*] == ){
ans++;
b[ans] = x*;
dfs(x*);
}
}
int main(){
scanf("%d",&n);
LL a[];
for(int i = ; i < n ; i ++){
cin>>a[i];
ma[a[i]] = ;
}
vector<LL>v;
for(int i = ; i < n ; i++){
ans = ;
b[] = a[i];
dfs(a[i]);
if(flag){
return ;
}
}
}

Codeforces977D ---Divide by three, multiply by two 深搜+map存出现的数的更多相关文章

  1. Divide by three, multiply by two(DFS+思维)

    Polycarp likes to play with numbers. He takes some integer number x, writes it down on the board, an ...

  2. Codeforces Round #479 (Div. 3) D. Divide by three, multiply by two

    传送门 D. Divide by three, multiply by two •题意 给你一个数 x,有以下两种操作,x 可以任选其中一种操作得到数 y 1.如果x可以被3整除,y=x/3 2.y= ...

  3. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  4. Network Saboteur (深搜递归思想的特殊使用)

    个人心得:对于深搜的使用还是不到位,对于递归的含义还是不太清楚!本来想着用深搜构成一个排列,然后从一到n分割成俩个数组,然后后面发现根本实现不了,思路太混乱.后来借鉴了网上的思想,发现用数组来标志,当 ...

  5. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  6. 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。

    利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...

  7. 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...

  8. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

  9. 深搜+回溯 POJ 2676 Sudoku

    POJ 2676 Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17627   Accepted: 8538 ...

随机推荐

  1. SecureCRT显示乱码的解决办法

    下面来看看SecureCRT的显示出现乱码这种情况.比如: 现在我们重新设置一下 设置下图中的配置 1.选择字符编码为UTF-8. 2.设置字符集为GB2312后保存好后确认退出. 3.再次测试一下.

  2. Windows 端口占用解决

  3. 数据库操作API 或万能的双下划线

    数据库操作API: 类型 描述 exact 精确匹配: polls.get_object(id__exact=14). iexact 忽略大小写的精确匹配: polls.objects.filter( ...

  4. vue:监听数据

    1:普通的监听: data () { return { watchNum:1, } }, watch: { watchNum(newValue, oldValue) { console.log(old ...

  5. 2319__1.5.3 Superprime Rib 特殊的质数肋骨

    [Submit][Status][Forum] Description 农民约翰母牛总是产生最好的肋骨. 你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们. 农民约翰确定他卖给买方的是真正的 ...

  6. eclipse 使用Maven deploy命令部署构建到Nexus

    转载于:http://blog.csdn.net/jun55xiu/article/details/43051627 1  应用场景:SYS-UTIL(系统工具)项目部署.构建成JAR包(SYS-UT ...

  7. weka连接mysql数据库

    一.下载并解压数据库驱动 下载地址:http://www.mysql.com/products/connector/,本文下载 mysql-connector-java-5.0.8.zip.将解压后的 ...

  8. 解决linux中ssh登录Warning:Permanently added (RSA) to the list of known hosts

    原因: 在执行scp id_rsa.pub root@hostname:/root/.ssh这一步时,没在本机的/root/.ssh下生成known_hosts文件. 解决方案: vi /etc/ss ...

  9. 【动态规划】最大子段和问题,最大子矩阵和问题,最大m子段和问题

    http://blog.csdn.net/liufeng_king/article/details/8632430 1.最大子段和问题      问题定义:对于给定序列a1,a2,a3……an,寻找它 ...

  10. 吴裕雄 30-MySQL 及 SQL 注入

    如果您通过网页获取用户输入的数据并将其插入一个MySQL数据库,那么就有可能发生SQL注入安全的问题.本章节将为大家介绍如何防止SQL注入,并通过脚本来过滤SQL中注入的字符.所谓SQL注入,就是通过 ...