传送门:点我

题意:给定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. vue中修改了数据但视图无法更新的情况[转载]

    我们有时候常碰到vue中明明修改了数据,但是视图无法更新,因此我总结了一点点碰到此类的情况: 1.v-for遍历的数组,当数组内容使用的是arr[0].xx =xx更改数据,vue无法监测到 数组数据 ...

  2. 机器学习入门-数值特征-数据四分位特征 1.quantile(用于求给定分数位的数值) 2.plt.axvline(用于画出竖线) 3.pd.pcut(对特征进行分位数切分,生成新的特征)

    函数说明: 1.  .quantile(cut_list) 对DataFrame类型直接使用,用于求出给定列表中分数的数值,这里用来求出4分位出的数值 2.  plt.axvline()  # 用于画 ...

  3. elasticsearch-cluster shards

    elasticsearch-cluster: Windows下本地测试用 创建集群就要给集群起名,修改 elasticsearch.yml文件. cluster.name: es_test //集群名 ...

  4. 学习别人的rpc框架

    https://my.oschina.net/huangyong/blog/361751 https://gitee.com/huangyong/rpc 在此文基础上的另一个实现,解决了原文中一些问题 ...

  5. centos磁盘空间重新分配

    将/home目录压缩一部分空间到/ ref: https://serverfault.com/a/811124/434124 https://stackoverflow.com/a/19969471/ ...

  6. C++指针理解

    指针是C/C++编程中的重要概念之一,也是最容易产生困惑并导致程序出错的问题之一.利用指针编程可以表示各种数据结构,通过指针可使用主调函数和被调函数之间共享变量或数据结构,便于实现双向数据通讯:指针能 ...

  7. 使用hibernate与mysql时数据不能插入的原因及解决办法

    1.背景 之前从没用过hibernate,因此在网上搜了一下hibernate快速入门方面的信息,最后我按照<Myeclipse Hibernate 快速入门 中文版>(CSDN,百度文库 ...

  8. 趣味编程:静夜思(Python版)

    from itertools import groupby def verticalWriting(txt, offset): l = lambda x: x[0] % offset for (_, ...

  9. 转:display:flex不兼容Android、Safari低版本的解决方案 【flex布局】

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. MVC part3

    SpringMVC原理图 SpringMVC接口解释 DispatcherServlet接口: Spring提供的前端控制器,所有的请求都有经过它来统一分发.在DispatcherServlet将请求 ...