这个题如果裸搜肯定超时了

但是我们可以枚举,用初始串的哪一位数字去填目标串的那一位数字

这样就是暴力6!,复杂度很低,然后需要解决过程中经过的点的问题,

因为是从左向右走,所以记录当前光标,

和当前达到的最右端

所以复杂度是O(T*36*(6!)),2000w的复杂度

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <string>
using namespace std;
typedef long long LL;
const int N=1e6+;
const int INF=0x3f3f3f3f;
int vis[N][][];
int f[]= {,,,,,};
int left(int x,int p)
{
int k1=x/f[p]%;
int k2=x/f[p-]%;
return x+(k2-k1)*f[p]+(k1-k2)*f[p-];
}
int right(int x,int p)
{
return left(x,p+);
}
int judge(int x,int y,int l,int r)
{
int ret=;
for(int i=l; i<=r; ++i)
ret+=abs((x/f[i]%)-(y/f[i]%));
return ret;
}
struct Node
{
int x,p,mx,step;
Node() {}
Node(int a,int b,int c,int d)
{
x=a;
p=b;
mx=c;
step=d;
}
};
queue<Node>q;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int s,t;
scanf("%d%d",&s,&t);
q.push(Node(s,,,));
vis[s][][]=++T;
int ans=INF;
while(!q.empty())
{
Node u=q.front();
q.pop();
if(u.step>=ans)continue;
if(u.p>)
{
Node v=u;++v.step;
--v.p;
if(vis[v.x][v.p][v.mx]!=T)
{
vis[v.x][v.p][v.mx]=T;
q.push(v);
}
}
if(u.p<)
{
Node v=u;
++v.p;++v.step;
v.mx=max(v.mx,v.p);
if(vis[v.x][v.p][v.mx]!=T)
{
vis[v.x][v.p][v.mx]=T;
if(judge(v.x,t,v.mx+,)==)
ans=min(ans,judge(v.x,t,,v.mx)+v.step);
q.push(v);
}
}
if(u.p>)
{
Node v=u;++v.step;
v.x=left(v.x,v.p);
if(vis[v.x][v.p][v.mx]!=T)
{
vis[v.x][v.p][v.mx]=T;
if(judge(v.x,t,v.mx+,)==)
ans=min(ans,judge(v.x,t,,v.mx)+v.step);
q.push(v);
}
}
if(u.p<)
{
Node v=u;++v.step;
v.x=right(v.x,v.p);
v.mx=max(v.mx,v.p+);
if(vis[v.x][v.p][v.mx]!=T)
{
vis[v.x][v.p][v.mx]=T;
if(judge(v.x,t,v.mx+,)==)
ans=min(ans,judge(v.x,t,,v.mx)+v.step);
q.push(v);
}
}
}
--T;
printf("%d\n",ans);
} return ;
}

SDUT 3571 Password 暴力搜索的更多相关文章

  1. ACM 暴力搜索题 题目整理

    UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...

  2. hdu 4740 The Donkey of Gui Zhou(暴力搜索)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...

  3. hdu 1427 速算24点 dfs暴力搜索

    速算24点 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem De ...

  4. 随手练——洛谷-P1151(枚举与暴力搜索)

    枚举 #include <iostream> using namespace std; int main() { ; cin >> k; ; i < ; i++) { ) ...

  5. 枚举进程——暴力搜索内存(Ring0)

    上面说过了隐藏进程,这篇博客我们就简单描述一下暴力搜索进程. 一个进程要运行,必然会加载到内存中,断链隐藏进程只是把EPROCESS从链表上摘除了,但它还是驻留在内存中的.这样我们就有了找到它的方法. ...

  6. [luogu 1092] 虫食算 (暴力搜索剪枝)

    传送门 Description Input 包含四行. 第一行有一个正整数 (N≤26). 后面的三行,每行有一个由大写字母组成的字符串,分别代表两个加数以及和.这3个字符串左右两端都没有空格,从高位 ...

  7. HDU 3131 One…Two…Five! (暴力搜索)

    题目链接:pid=3131">HDU 3131 One-Two-Five! (暴力搜索) 题意:给出一串数字,要求用加,减,乘,除(5/2=2)连接(计算无优先级:5+3*6=8*6= ...

  8. 吴裕雄 python 机器学习——模型选择参数优化暴力搜索寻优GridSearchCV模型

    import scipy from sklearn.datasets import load_digits from sklearn.metrics import classification_rep ...

  9. POJ 1129:Channel Allocation 四色定理+暴力搜索

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13357   Accepted: 68 ...

随机推荐

  1. http://www.aboutyun.com/thread-6551-1-1.html

    http://www.aboutyun.com/thread-6551-1-1.html

  2. js中的call、apply

    function qingyezhuA(a0, a1) { this.qingyezhuX = a0 + a1; } var qingyezhuObj1 = { }; qingyezhuA.apply ...

  3. 套题T3

    秋实大哥与线段树 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  ...

  4. 【Linux高频命令专题(15)】more

    more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...

  5. Android学习之-TextView的滑动效果

    textView中如何设置滚动条 在xml中定义: <TextView            android:layout_width="wrap_content"      ...

  6. 使用Retrofit时出现 java.lang.IllegalArgumentException: URL query string "t={type}&p={page}&size={count}" must not have replace block. For dynamic query parameters use @Query.异常原因

    /** * Created by leo on 16/4/30. */ public interface GanchaiService { @GET("digest?t={type}& ...

  7. 转 Difference between WCF and Web API and WCF REST and Web Service

    http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and-WCF-R ...

  8. 单交换机VLAN虚拟局域网划分

    1.下载Cisco模拟器 Packet Tracer 是由Cisco公司发布的一个辅助学习工具,为学习CCNA课程的网络初学者去设计.配置.排除网络故障提供了网络模拟环境.学生可在软件的图形用户界面上 ...

  9. javascript精确计算

    一篇文章: 4 个用于执行高级数学计算的 JavaScript 库 numbers.js  Numeric Javascript accounting.js Tangle 有时只需要加减乘法能精确,没 ...

  10. NLP基本任务-nltk_data文本分割

    将文本分割为句子 nltk.sent_tokenize(text,language) text:需要分割的文本 language:语言种类 czech捷克语 danish丹麦语 dutch荷兰语 en ...