Jokewithpermutation (DFS)
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)的更多相关文章
- UVALive 6948 Jokewithpermutation dfs
题目链接:UVALive 6948 Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...
- DFS Gym 100553J Jokewithpermutation
题目传送门 /* 题意:将字符串分割成一个全排列 DFS:搜索主要在一位数和两位数的处理,用d1, d2记录个数,在不饱和的情况下,两种都试一下 DFS还是写不来,难道是在家里懒? */ #inclu ...
- BZOJ 3083: 遥远的国度 [树链剖分 DFS序 LCA]
3083: 遥远的国度 Time Limit: 10 Sec Memory Limit: 1280 MBSubmit: 3127 Solved: 795[Submit][Status][Discu ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- BZOJ 4196: [Noi2015]软件包管理器 [树链剖分 DFS序]
4196: [Noi2015]软件包管理器 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1352 Solved: 780[Submit][Stat ...
- 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)
图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...
- BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]
2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 2545 Solved: 1419[Submit][Sta ...
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
- 深度优先搜索(DFS)
[算法入门] 郭志伟@SYSU:raphealguo(at)qq.com 2012/05/12 1.前言 深度优先搜索(缩写DFS)有点类似广度优先搜索,也是对一个连通图进行遍历的算法.它的思想是从一 ...
随机推荐
- flume-kafka-storm-hdfs-hadoop-hbase
# bigdata-demo 项目地址: https://github.com/windwant/bigdata-demo.git hadoop: hadoop hdfs操作 log输出到flume ...
- Python全栈 Web(概述、HTML基础语法)
原文地址: https://yq.aliyun.com/articles/631222 ........................................................ ...
- node事件循环
Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调用,并处理并发. Node.j ...
- 【转】Unity 使用xLua遇到的坑
在我们使用xLua作为Unity中lua集成的解决方案时,遇到了一个问题,就是当我们使用在lua中把UI中的某个控件绑定相应的事件(如按钮的onClick事件),xLua绑定这个事件是用委托实现的,具 ...
- Y460蓝牙键盘无法连接问题解决
mac坏了,无法启动,一直没时间去修理. 近期把大学的时候用的笔记本又翻了出来,小Y,经典的“娱乐本” Y460. Y460上之前被自己各种重装系统,反复从windows到双系统,再到linux之间来 ...
- 【Linux】Face Recognition的封装
使用虹软的人脸识别 写了一个linux下的Face Recognition的封装,当作是练习. C++的封装,结合opencv,使用方便.https://github.com/zacario-li/F ...
- Paper Reading - Show, Attend and Tell: Neural Image Caption Generation with Visual Attention ( ICML 2015 )
Link of the Paper: https://arxiv.org/pdf/1502.03044.pdf Main Points: Encoder-Decoder Framework: Enco ...
- Centos/Linux 下升级python2.7至3.5.0
(一) 安装Python3.5 (1)在安装python之前,因为linux系统下默认没有安装wget,gcc,首先安装wget,gcc: [root@node6 python_scripts]# y ...
- POSIX线程学习
一.什么是线程 在一个程序中的多个执行路线就叫做线程.更准确的定义是:线程是一个进程内部的一个控制序列.所有的进程都至少有一个线程.当进程执行fork调用时,将创建出该进程的一份新副本,这个新进程拥有 ...
- ACM 第九天
动态规划1 动态规划问题是面试题中的热门话题,如果要求一个问题的最优解(通常是最大值或者最小值),而且该问题能够分解成若干个子问题,并且小问题之间也存在重叠的子问题,则考虑采用动态规划. 1.LLS ...