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. labview--http协议数据交互

    最近接了一个项目,需求是要将采集到的数据,以以下要求上报,并且提供接口供上层系统下发指令. 采用restful的http协议进行交互: 输入输出参数皆为json体. 响应包含三部分: Code:业务码 ...

  3. 利用爬虫、SMTP和树莓派3B发送邮件&续集&(爬取墨迹天气预报信息)

    -----------------------------------------------学无止境----------------------------------------------- 前 ...

  4. Ubuntu 16.04 安装显卡驱动后循环登录和无法设置分辨率的一种解决方案

    1. 安装环境 电脑:MSI GP63 显卡:GeForce GTX 1070 系统:Ubuntu 16.04 驱动版本:NVIDIA 384.130 2. 循环登录 如果按照这篇文章 Ubuntu ...

  5. LeetCode - 412. Fizz Buzz - ( C++ ) - 解题报告 - to_string

    1.题目大意 Write a program that outputs the string representation of numbers from 1 to n. But for multip ...

  6. Java Class Object

    Object类 它是所有类的基类. public class Person { } //实际上是 public class Person extends Object { } Object类的方法 t ...

  7. UBUNTU如何安装tar.gz版的flash

    adobe flash player的官方下载页面为:https://get.adobe.com/cn/flashplayer/ 不过近期通过APT方式以及ubuntu的软件中心都安装不了flashp ...

  8. python学习笔记01:安装python

    下载python: 从从https://www.python.org/downloads/下载python,根据操作系统的不同,选择不同的版本下载.注意:linux系统大多预装了python,可以直接 ...

  9. css滤镜让图片模糊

    .mhblur { filter: url(blur.svg#blur); /* FireFox, Chrome, Opera */ -webkit-filter: blur(53px); /* Ch ...

  10. Qt在VS(Visual Studio)中使用

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt在VS(Visual Studio)中使用     本文地址:https://www.te ...