3087POJ
来源:互联网 发布:linux能运行在arm上吗 编辑:程序博客网 时间:2024/05/18 01:53
这道题给你两部分木块。问你能否到达目标状态。注意是先放堆2,然后再放堆1,我们直接搜就好了。写一个生成状态函数,然后与目标状态比较。
#include<iostream>#include<cstdio>#include<string.h>#include<string>#include<stack>#include<set>#include<algorithm>#include<cmath>#include<vector>#include<map>#include<queue>#define ll __int64#define lll unsigned long long#define MAX 10000009#define MAXN 2009#define eps 1e-8#define INF 0x7fffffff#define mod 1000000007#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1using namespace std;string s,s1,s2;int num,m;string ok(string x,string y){ string ans =""; for(int i = 0; i<m; i++) { ans+=y[i]; ans+=x[i]; } return ans;}int solve(){ map<string,bool>mp; string str = ok(s1,s2); if(s==str) { return 1; } //cout<<str<<endl; while(mp.find(str)==mp.end())//判断map.find如果没有找到,会返回结束位置的迭代器,map.end()是map的尾部,我认为这里是第一遍到达str的状态等于map.end(),存在map的尾部,当再次到达str时候,str不存在map尾部,所以就结束循环
{ mp[str] = true; s1 = str.substr(0,m); s2 = str.substr(m,m); str = ok(s1,s2); //cout<<s<<endl; num++; if(s==str) { return num; } } return -1;}int main(){ //freopen("ans.txt","r",stdin); int T; scanf("%d",&T); for(int cas = 1; cas<=T; cas++) { scanf("%d",&m); num = 1; cin>>s1>>s2>>s; cout<<cas<<" "<<solve()<<endl; } return 0;}
0 0
- POJ 3087
- poj 3087
- POJ 3087
- poj-3087
- poj 3087
- poj 3087
- 3087POJ
- poj--3087
- POJ 3087
- poj 3087
- POJ 3087
- POJ 3087
- POJ 3087
- poj 3087解题报告
- Poj 3087 (bfs)
- poj 3087 模拟
- poj 3087 模拟
- poj 3087 模拟题
- 微信本地调试、ngrok、tunnel
- 类与对象(二)
- HDU 4741
- 南邮 OJ 2076 天神小学
- 剑指offer刷题之java实现的二维数组中的查找
- 3087POJ
- [算法专题] 深度优先搜索&回溯剪枝
- 寻找一个二维数组鞍点的算法实现
- 关于StringBuffer.setLength和trimToSize
- [算法专题] 深度优先搜索&回溯剪枝
- 80%的业绩掌握在20%的客服手中
- 手把手教你如何加入到github的开源世界
- [算法专题] 深度优先搜索&回溯剪枝
- 南邮 OJ 2077 Dreaming