[ZOJ 1004] Anagrams by Stack (简单搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1004
题目大意:给你个栈,给你源串和目标串,按字典序输出符合要求的进站出站序列。
就是搜搜搜呗。。。
带上答案和模拟的栈。。
代码:
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <cmath>
#include <numeric>
using namespace std; typedef long long LL; char s[],t[]; void dfs(int now,int pp,int len,string ns,string st){
if( pp==len ){
for(int i=;i<st.size();i++){
putchar(st[i]);
putchar(' ');
if( i==st.size()- ) puts("");
}
return;
}
if( st.size()==len+len ) return;
dfs(now+,pp,len,ns+s[now],st+"i");
if( !ns.empty() && ns[ns.size()-] == t[pp] ){
ns.erase(--ns.end());
dfs(now,pp+,len,ns,st+"o");
}
} int main(){
while(scanf("%s%s",s,t)!=EOF){
puts("[");
int len = strlen(s);
string aa,bb;
dfs(,,len,aa,bb);
puts("]");
}
return ;
}
[ZOJ 1004] Anagrams by Stack (简单搜索)的更多相关文章
- stack+DFS ZOJ 1004 Anagrams by Stack
题目传送门 /* stack 容器的应用: 要求字典序升序输出,所以先搜索入栈的 然后逐个判断是否满足答案,若不满足,回溯继续搜索,输出所有符合的结果 */ #include <cstdio&g ...
- ZOJ 1004 Anagrams by Stack
Anagrams by Stack 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1004 题意:通过堆栈实现将一 ...
- ZOJ 1004 Anagrams by Stack(DFS+数据结构)
Anagrams by Stack 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4 题目大意:输入两个字符串序列,判 ...
- [ZJU 1004] Anagrams by Stack
ZOJ Problem Set - 1004 Anagrams by Stack Time Limit: 2 Seconds Memory Limit: 65536 KB How can a ...
- 1004 Anagrams by Stack
考察DFS的应用,用栈描述字符串的变化过程. #include <stdio.h> #include <string.h> int len1,len2; ],str2[],st ...
- Anagrams by Stack(深度优先搜索)
ZOJ Problem Set - 1004 Anagrams by Stack Time Limit: 2 Seconds Memory Limit: 65536 KB How can a ...
- 【Acm】算法之美—Anagrams by Stack
题目概述:Anagrams by Stack How can anagrams result from sequences of stack operations? There are two seq ...
- HDU ACM 1515 Anagrams by Stack
Anagrams by Stack Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- ElasticSearch 5学习(4)——简单搜索笔记
空搜索: GET /_search hits: total 总数 hits 前10条数据 hits 数组中的每个结果都包含_index._type和文档的_id字段,被加入到_source字段中这意味 ...
随机推荐
- android 旋转手机的时候,如何忽略onCreate再次被系统调用?
实现一个程序,主要是不想在手机横竖屏的时候重新onCreate,所以在配置文件中增加了配置选项: android:configChanges="orientation|keyboardHid ...
- 彻底解决ASP.NET MVC 3 404错误码返回302的问题
转自:http://blog.csdn.net/mycloudke/article/details/9746333 404状态码:,意味着当在页面上显示用户点击不存在,提高用户体验度,搜索引擎会放弃这 ...
- [spring] java.lang.reflect.MalformedParameterizedTypeException
spring中加入dubbo后报java.lang.reflect.MalformedParameterizedTypeException 因为dubbo 2.5.3 它引用的是spring 2.5. ...
- [tomcat] tomcat+nginx 负载均衡配置
首先下载,安装tomcat. 修改tomcat端口,修改server.xml: 1.修改tomcat端口(默认8080) <Connector port="8383" pro ...
- IsolatedStorageException for Silverlight Application
if you are using the IsolatedStorage for application configuration storage, and when you get the Iso ...
- (转)如何在eclipse的配置文件里指定jdk路径
本文转载自:http://songguoliang.iteye.com/blog/1752519 运行eclipse时报如下错误: 在eclipse的配置文件里指定jdk路径,只需在eclipse的配 ...
- (C# File) 文件操作
Get Files from Directory [C#] This example shows how to get list of file names from a directory (inc ...
- PLSQL_性能优化系列20_Oracle Result Cash结果缓存
20150528 Created By BaoXinjian
- H桥电路
电路特点:有三极管组成4个桥的腿,中间可以使电容或是电机. 应用:直流电机的正反转控制.DC-AC逆变电源(脉冲直流变为周期交流) 关键点:同一个时刻只能对角的一对三极管导通,同侧不能一块导通,共2对 ...
- PHP $_SERVER['HTTP_REFERER'] 获取前一页面的 URL 地址
PHP $_SERVER['HTTP_REFERER'] 使用 $_SERVER['HTTP_REFERER'] 将很容易得到链接到当前页面的前一页面的地址.一个例子如下: index.php(实际地 ...