Problem J. Jokewithpermutation

Input file: joke.in
Output file: joke.out

Joey had saved a permutation of integers from 1 to n in a text file. All the numbers were written as
decimal numbers without leading spaces.
Then Joe made a practical joke on her: he removed all the spaces in the file.
Help Joey to restore the original permutation after the Joe’s joke!
Input
The input file contains a single line with a single string — the Joey’s permutation without spaces.
The Joey’s permutation had at least 1 and at most 50 numbers.
Output
Write a line to the output file with the restored permutation. Don’t forget the spaces!
If there are several possible original permutations, write any one of them.
Sample input and output
joke.in joke.out

4111109876532           4 1 11 10 9 8 7 6 5 3 2

这是区域赛的题目!!!!

DFS 暴力搜索 看了yan的代码  自己理解了一下

注意几点  1.vetor的使用 姿势

2.字符串长度判断最大n

3.一位或二位字符组成一个数

4.dfs姿势要熟练!!!!!

#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
vector<int>re;
int s=;
int po;
char a[];
int len;
void dfs(int n)
{
if(n==len)
{
int flag=;
for(int i=;i<=s;i++)
{
if(!mp[i])
flag=;
}
//cout<<re.size()<<endl;
if(flag)
{
for(unsigned int i=;i<re.size()-;i++)
printf("%d ",re[i]);
printf("%d\n",re[re.size()-]);
po=;
}
return ;
}
if(po)
return ;
if(!mp[a[n]-''])
{
mp[a[n]-'']=;
re.push_back(a[n]-'');
dfs(n+);
if(po)
return ;
re.pop_back();
mp[a[n]-'']=;
}
if(!mp[(a[n]-'')*+a[n+]-'']&&((a[n]-'')*+a[n+]-'')<=s&&po==&&n+<len)
{
mp[(a[n]-'')*+a[n+]-'']=;
re.push_back((a[n]-'')*+a[n+]-'');
dfs(n+);
if(po)
return;
mp[(a[n]-'')*+a[n+]-'']=;
re.pop_back();
}
}
int main()
{
freopen("joke.in","r",stdin);
freopen("joke.out","w",stdout);
gets(a);
len=strlen(a);
re.clear();
mp.clear();
if(len<=)
{
for(int i=; i<len-; i++)
printf("%c ",a[i]);
printf("%c\n",a[len-]);
return ;
}
po=;
s=(len-)/+;
dfs();
return ;
}

Jokewithpermutation (DFS)的更多相关文章

  1. UVALive 6948 Jokewithpermutation dfs

    题目链接:UVALive 6948  Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...

  2. DFS Gym 100553J Jokewithpermutation

    题目传送门 /* 题意:将字符串分割成一个全排列 DFS:搜索主要在一位数和两位数的处理,用d1, d2记录个数,在不饱和的情况下,两种都试一下 DFS还是写不来,难道是在家里懒? */ #inclu ...

  3. BZOJ 3083: 遥远的国度 [树链剖分 DFS序 LCA]

    3083: 遥远的国度 Time Limit: 10 Sec  Memory Limit: 1280 MBSubmit: 3127  Solved: 795[Submit][Status][Discu ...

  4. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  5. BZOJ 4196: [Noi2015]软件包管理器 [树链剖分 DFS序]

    4196: [Noi2015]软件包管理器 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1352  Solved: 780[Submit][Stat ...

  6. 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)

    图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...

  7. BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]

    2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 2545  Solved: 1419[Submit][Sta ...

  8. POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)

    来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS   Memory Limit: 65536 ...

  9. 深度优先搜索(DFS)

    [算法入门] 郭志伟@SYSU:raphealguo(at)qq.com 2012/05/12 1.前言 深度优先搜索(缩写DFS)有点类似广度优先搜索,也是对一个连通图进行遍历的算法.它的思想是从一 ...

随机推荐

  1. Java开发工程师(Web方向) - 03.数据库开发 - 第4章.事务

    第4章--事务 事务原理与开发 事务Transaction: 什么是事务? 事务是并发控制的基本单位,指作为单个逻辑工作单元执行的一系列操作,且逻辑工作单元需满足ACID特性. i.e. 银行转账:开 ...

  2. JAVA基础学习之路(五)数组的定义及使用

    什么是数组:就是一堆相同类型的数据放一堆(一组相关变量的集合) 定义语法: 1.声明并开辟数组 数据类型 数组名[] = new 数据类型[长度]: 2.分布完成 声明数组:数据类型 数组名 [] = ...

  3. halcon安装提示could not write updated path to HKLM

    halcon安装提示could not write updated path to HKLM 我们在安装Halcon软件时,会弹出如上图错误信息,这个错误信息提示软件无法写入本地注册表,造成这个原因有 ...

  4. Centos下的SVN搭建

    需求: 搭建SVN实现本地开发环境,方便线上代码的更新. 步骤: 1. 安装SVN服务 yum install -y subversion 2.创建SVN代码库的目录.创建版本库 mkdir -p / ...

  5. Java实验二实验报告:java面向对象程序设计

    java实验二实验报告 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计模式 实验 ...

  6. Mininet实验 MAC地址学习分析

    拓扑图 学习过程分析 首先交换机A和交换机B一开始的MAC地址表都是空的. 此时主机11向主机33发送一个数据帧. 数据帧会先到达交换机A,交换机A会获得主机11的MAC地址和端口号.(此时交换机A的 ...

  7. DAY2敏捷冲刺

    站立式会议 工作安排 (1)服务器配置 (2)数据库连接 (3)页面创意 燃尽图 代码提交记录 感想 林一心:centos配置服务器真的算是一个不小的坑,目前数据库配置清楚,脚本部署好明天测试交互,还 ...

  8. iOS- UIPickerView餐厅点餐系统

    在餐厅里的点餐系统的核心控件就是UIPickerView 今天晚上在整理以前的项目笔记时,特意把UIPickerView单独拿出来,做了一个简陋的点餐道具. 因为没有素材图片,所有大家将就看看吧 0. ...

  9. Css入门课程 Css文本样式

    文字是网页的非常基础的内容,文本的样式设置也是非常重要的 1 字体大小 font-size:绝对大小单位和相对大小单位,绝对大小单位有cm,mm in(厘米,毫米,英寸)等,这是大小不随屏幕分辨率大小 ...

  10. HTML页面垂直滚动条不见

    <body style="overflow-y:scroll;"> </body>