Codeforces977D ---Divide by three, multiply by two 深搜+map存出现的数
传送门:点我
题意:给定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存出现的数的更多相关文章
- 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 ...
- 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= ...
- 2015暑假多校联合---Cake(深搜)
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...
- Network Saboteur (深搜递归思想的特殊使用)
个人心得:对于深搜的使用还是不到位,对于递归的含义还是不太清楚!本来想着用深搜构成一个排列,然后从一到n分割成俩个数组,然后后面发现根本实现不了,思路太混乱.后来借鉴了网上的思想,发现用数组来标志,当 ...
- HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others) ...
- 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。
利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...
- 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 ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- 深搜+回溯 POJ 2676 Sudoku
POJ 2676 Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17627 Accepted: 8538 ...
随机推荐
- Ubuntu 安装微信
参考:https://blog.csdn.net/deeposcar/article/details/80710843
- react-native-vector-icons 图标库使用
安装链接 yarn add react-native-vector-icons react-native link react-native-vector-icons 在项目工程中打开 .xcodep ...
- PE 装机
PE 装机 下载PE安装到硬盘启动. 下载win7安装原始文件ISO镜像文件,解压ISO到文件夹. 重启电脑,选择PE菜单. 打开windows安装器大全>选择 winntSetup> i ...
- javascript:控制一个元素高度始终等于浏览器高度
window.onresize = function(){ this.opHtight()} //给浏览器添加窗口大小改变事件window.onresize = function(){ this.op ...
- 2339 3.1.1 Agri-Net 最短网络
Description 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场.当然,他需要你的帮助. 约翰已经给他的农场安排了一条高速的网络线路,他想把这条线路共享 ...
- The value for the useBean class attribute xxx is invalid
JSP页面报这个错可能的原因: 1:指定的 Bean 类没找到 2:该类不是 public 的,或者找到的 class 文件是 interface 或抽象类 3:Bean 类中没有 public 的无 ...
- python实现查找算法:二分查找法
二分查找算法也称折半查找,基本思想就是折半,和平时猜数字游戏一样,比如猜的数字时67,猜测范围是0-100,则会先猜测中间值50,结果小了,所以就会从50-100猜测,中间值为75,结果大了,又从50 ...
- ArcGIS自定义工具箱-判断字段值是否相等
ArcGIS自定义工具箱-判断字段值是否相等 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:判断两个字段值是否相等 使用方法: 结果: 联系方式:谢老师,13 ...
- winform clickonce在线安装
转 http://swanmsg.blog.sohu.com/162994305.html
- Cascade Classifier Training 没有基础也会目标检测啦
Cascade Classifier Training 具体自己看: http://docs.opencv.org/2.4.13.2/doc/user_guide/ug_traincascade.ht ...