HNU Joke with permutation (深搜dfs)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=13341&courseid=0
| Joke with permutation |
| Time Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KB |
| Total submit users: 85, Accepted users: 57 |
| Problem 13341 : Special judge |
| Problem description |
|
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 Help |
| Input |
|
The input file contains a single line with a single string — the Joey’s The Joey’s permutation had at least 1 and at |
| Output |
|
Write a line to the output file with the restored permutation. Don’t forget If there are several possible original permutations, write |
| Sample Input |
4111109876532 |
| Sample Output |
4 1 11 10 9 8 7 6 5 3 2 |
| Problem Source |
| NEERC 2014 |
| Submit Discuss Judge Status Problems Ranklist |
题目大意:将一串完整的字符串分成1~n个数。将空格补进去,并将其输出。
解题思路:1、注意这个n是可以求出来的
2、一个数字一个数字比较,只要满足这个数字小于n,还有保证这个数字没有访问过就ok啦
详见代码。
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int n,flag;
char ch[];
int ans[];
bool vis[]; bool dfs(int i,int k)
{
if (flag==)
return true;
if (k==n+)
{
for (int i=;i<k-;i++)
{
printf ("%d ",ans[i]);
}
printf ("%d\n",ans[k-]);
flag=;
return true;
}
if (ch[i]-''<=n&&!vis[ch[i]-'']&&ch[i]-''>)
{
ans[k]=ch[i]-'';
vis[ch[i]-'']=;
if(dfs(i+,k+)) return true;
vis[ch[i]-'']=;
}
if ((ch[i]-'')*+ch[i+]-''<=n&&(ch[i]-'')*+ch[i+]-''>&&!vis[(ch[i]-'')*+ch[i+]-''])
{
ans[k]=(ch[i]-'')*+ch[i+]-'';
vis[(ch[i]-'')*+ch[i+]-'']=;
if(dfs(i+,k+)) return true;
vis[(ch[i]-'')*+ch[i+]-'']=;
}
return false;
} int main()
{
while (scanf("%s",ch)!=EOF)
{
flag=;
memset(ans,,sizeof(ans));
memset(vis,,sizeof(vis));
int len=strlen(ch);
if (len>)
n=(len-)/+;
else
n=len;
dfs(,);//dfs();
}
return ;
}
HNU Joke with permutation (深搜dfs)的更多相关文章
- 图的遍历 之 深搜dfs
DFS 遍历 深度优先搜索是一个递归过程,有回退过程. 对一个无向连通图,在访问图中某一起始顶点u 后,由u 出发,访问它的某一邻接顶点v1:再从v1 出发,访问与v1 邻接但还没有访问过的顶点v2: ...
- HDU 2553 N皇后问题(深搜DFS)
N皇后问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 深搜(DFS),Image Perimeters
题目链接:http://poj.org/problem?id=1111 解题报告: 1.这里深搜有一点要注意,对角线上的点,如果为'.',则total不应该增加,因为这不是他的边长. #include ...
- 深搜(DFS),回溯,Fire Net
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=2 解题报告: 这里的深搜有一点不同,就是,在深搜每一个点时,都要深搜每 ...
- 算法学习笔记(六) 二叉树和图遍历—深搜 DFS 与广搜 BFS
图的深搜与广搜 复习下二叉树.图的深搜与广搜. 从图的遍历说起.图的遍历方法有两种:深度优先遍历(Depth First Search), 广度优先遍历(Breadth First Search),其 ...
- 【深搜(DFS)-例题-踏青】-C++
描述 小白和他的朋友周末相约去召唤师峡谷踏青.他们发现召唤师峡谷的地图是由一块一块格子组成的,有的格子上是草丛,有的是空地.草丛通过上下左右 4 个方向扩展其他草丛形成一片草地,任何一片草地中的格子都 ...
- 【LeetCode】深搜DFS(共85题)
[98]Validate Binary Search Tree [99]Recover Binary Search Tree [100]Same Tree [101]Symmetric Tree [1 ...
- HDU 2614 Beat 深搜DFS
这道题目还是比较水的,但是题意理解确实费了半天劲,没办法 谁让自己是英渣呢! 题目大意: 猪脚要解决问题, 他有个习惯,每次只解决比之前解决过的问题的难度要大. 他给我们一个矩阵 矩阵的 i 行 j ...
- noj电子老鼠走迷宫(深搜dfs)超时错误
1042.电子老鼠闯迷宫 时限:1000ms 内存限制:10000K 总时限:3000ms 描述 有一只电子老鼠被困在如下图所示的迷宫中.这是一个12*12单元的正方形迷宫,黑色部分表示建筑物,白色 ...
随机推荐
- C#开发移动应用 - 环境搭建
前言 其实从2013开始就想用Xamarin,奈何 当初收费一座大山压在身上 完全无法见得庐山真面目 后面2015,微软收购Xamarin,没过多久就宣布对个人用户免费..那个兴奋劲就别提了.. 兴奋 ...
- [LeetCode] PathSum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- 第120天:移动端-Bootstrap基本使用方法
一.Bootstrap使用 1.搭建Bootstrap页面骨架及项目目录结构 ``` ├─ /weijinsuo/ ··················· 项目所在目录 └─┬─ /css/ ···· ...
- web端调百度地图页面
在点击进入地图的入口(下面数据是vue渲染的数据) <a class="navigation" v-if="merchant.longitude && ...
- [您有新的未分配科技点]博弈论进阶:似乎不那么恐惧了…… (SJ定理,简单的基础模型)
这次,我们来继续学习博弈论的知识.今天我们会学习更多的基础模型,以及SJ定理的应用. 首先,我们来看博弈论在DAG上的应用.首先来看一个小例子:在一个有向无环图中,有一个棋子从某一个点开始一直向它的出 ...
- [BZOJ1503][NOI2004]郁闷的出纳员 无旋Treap
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MB Description OIER公司是一家大型专业化软件公司,有着数以万计的员 ...
- [ZJOI2014]力 FFT
题面 题解: \[F_j = \sum_{i < j}\frac{q_iq_j}{(i - j)^2} - \sum_{i > j}{\frac{q_iq_j}{(i - j)^2}}\] ...
- ros error : c++: error: $(catkin_LIBRARIES): 没有那个文件或目录
卧槽,真是........................瞎眼了. 一个半小时才找出错误来..... c++: error: $(catkin_LIBRARIES): 没有那个文件或目录 Oh my ...
- poj 1185 状态压缩
炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 27926 Accepted: 10805 Descriptio ...
- NYOJ--703
原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=703 分析:先考虑不受限制的情况,此时共可以修n*(n-1)/2条隧道:所有的place组 ...