7263 Today Is a Rainy Day Today is a rainy day. The temperature is apparently lower than yesterday. Winter is coming. It always leaves people feeling fatigued and tired. Lee hasn’t prepared for winter yet. As he wakes up this morning, he looks out of the window. Yesterday’s shining sunlight can no longer be seen. It is dark outside. The sky looks so heavy that it may collapse down at any moment. Lee gets out of his bed, shakes his head slightly to make himself more awake. But it’s of no use for him. Then he goes to the restroom and washes up. Lee has a class in fifteen minutes. If he sets out immediately, he may gets to the classroom on time. But he is not in the mood to do so. He decides to skip class and does something more interesting to train his mind. He takes out a draft paper and writes a list of digits using a dice. It is obvious that the digits are all between 1 and 6. And then he applies two kind of modifications to the digits. The first kind is to modify one digit into another. The second kind is to modify one kind of digits into another. For example, he can modify “12123” to “12121” using the first kind of modification, or modify “12123” to “13133” using the second kind of modification. In the process of modification, all digits should be in {1, 2, 3, 4, 5, 6}; After a few modifications, he feels tired but pleased. He’s got a list of digits which is very different from the original one. Thinking of the next thing to do, Lee becomes a little excited. He is going to figure out the least number of modifications to transform the final list back to the original one using the same rules. Lee made it in a very short time. Can you do this like him? Input There are up to 100 test cases. For each test case, there are two lines containing two lists of digits, representing the original list and the final list in order. The digits are all between 1 and 6. It is guaranteed that two lists are of same length. The length will not be greater than 110. Output For each test case, output one integer, the answer. Sample Input 22345611 12345611 2234562221 1234561221 2234562211 1234561111 22345622112 12345611111 654321654321654321654321 123456123456123456123456 ACM-ICPC Live Archive: 7263 – Today Is a Rainy Day 2/2 Sample Output 1 2 3 3 11

题目链接:给你两个字符由1到6组成的a,b字符串(长度<=110),现在你有两种操作,1.将其中某个字符改成另一个,2.将某种字符改成另一种。求从b字符串变换到a字符串所需要的最少步数。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
#define CT continue
#define SC scanf
const int N=1e6;
int dp[N],state[N];
char sa[120],sb[120];
int cnt=0,x[7],savex[7],len; int getn()
{
int res=0;
for(int i=1;i<=6;i++) res=res*10+x[i];
return res;
} queue<int> q;
void presolve()
{
for(int i=1;i<=6;i++) x[i]=i;
MM(dp,inf);
state[++cnt]=getn();
dp[state[cnt]]=0;
q.push(state[cnt]);
while(q.size()){
int u=q.front();q.pop();
for(int i=6;i>=1;i--) {x[i]=u%10;u/=10;}
memcpy(savex,x,sizeof(x));
int ori=getn();
for(int i=1;i<=6;i++)
for(int j=1;j<=6;j++){
memcpy(x,savex,sizeof(x));
for(int k=1;k<=6;k++)
if(x[k]==i) x[k]=j;
int lat=getn();
if(dp[lat]>dp[ori]+1){
if(dp[lat]==inf) state[++cnt]=lat;
dp[lat]=dp[ori]+1;
q.push(lat);
}
}
}
} int f[8][8],num[8];
int main()
{
presolve();
while(~SC("%s%s",sa,sb)){
int ans=inf;
MM(f,0);MM(num,0);
for(int i=0;sa[i]!='\0';i++){
int a=sa[i]-'0',b=sb[i]-'0';
f[b][a]++;
num[b]++;
}
for(int i=1;i<=cnt;i++){
int step=dp[state[i]],st=state[i];
for(int i=6;i>=1;i--) {x[i]=st%10;st/=10;}
for(int i=1;i<7;i++) {
step+=num[i]-f[i][x[i]];
}
ans=min(ans,step);
}
printf("%d\n",ans);
}
return 0;
}

  分析:题解链接

LA 7263 Today Is a Rainy Day bfs+暴力 银牌题的更多相关文章

  1. UVALive - 7263 Today Is a Rainy Day(bfs)

    原题链接 题意 给两个等长的只含数字1,2,3,4,5,6的字符串s(|s|≤110),有两种操作: - 把一个位置的数字换成另一个数字,换成的数字也只能是1到6- 把这个字符串中相同的数字都换成另一 ...

  2. hdoj5024【BFS/暴力】

    题意: 在可以行走的区域内,只能转一次90度的弯,问你最长这条路可以多长. 思路: 我们可以看到 /* 123 8 4 765 */ 转90度的路径会是横竖,也就是1-3-5-7; 还有斜的:2-4- ...

  3. LA 6621 /ZOJ 3736 Pocket Cube 打表+暴力

    这道题是长沙区域赛的一道简单题,当时题目在ZOJ重现的时候就做了一次,但是做的好复杂,用的BFS暴力,而且还没打表,最后还是莫名其妙的爆栈错误,所以就一直没弄出来,昨天做到大白书上例题05年东京区域赛 ...

  4. HDU 1312 (BFS搜索模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1312 题目大意:问迷宫中有多少个点被访问. 解题思路: DFS肯定能水过去的.这里就拍了一下BFS. ...

  5. POJ 3369 Meteor Shower (BFS,水题)

    题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...

  6. foj 2150 Fire Game(bfs暴力)

         Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M ...

  7. 并查集+bfs+暴力滑窗 Codeforces Round #356 (Div. 2) E

    http://codeforces.com/contest/680/problem/E 题目大意:给你一个n*n的图,然后图上的 . (我们下面都叫做‘点’)表示可以走,X表示不能走,你有如下的操作, ...

  8. Vladik and Favorite Game CodeForces - 811D (思维+BFS+模拟+交互题)

    D. Vladik and Favorite Game time limit per test 2 seconds memory limit per test 256 megabytes input ...

  9. Gym 101617J Treasure Map(bfs暴力)

    http://codeforces.com/gym/101617/attachments 题意:给出一个图,每个顶点代表一个金矿,每个金矿有g和d两个值,g代表金矿初始的金子量,d是该金矿每天的金子量 ...

随机推荐

  1. PostgreSQL练习3

    select dname,count(ename),avg(sal),sum(sal) from emp e,dept d where e.deptno=d.deptno group by dname ...

  2. Laravel框架与ThinkPHP框架的不同

    作为一个PHP菜鸟初学Laravel框架 在学习过程中我发现了其与TP框架的不同点,由于时间问题和认识还不够完善我先写出其中几点,有错误的地方希望各位大牛斧正... 1.渲染模版方式的不同:在Lara ...

  3. PHP内存管理-zendMM

    ZendMM 是zend memory manager zendMM可以分为三层: 1.存储层 维护者不同体量内存的hash表,已提供堆层使用,负责向os申请和释放内存 2.堆层 PHP内存管理的核心 ...

  4. ubuntu+nginx+uwsgi部署django web项目

    前言 将本地开发的django项目部署至linux上的uwsgi服务器,并配置nginx,完成基于ubuntu+nginx+uwsgi的上线运行.下面整理相关步骤. 服务器配置virtualenv 如 ...

  5. jQuery Validation ,调用valid方法时,不验证remote

    1.问题描述 model代码如下: remote对应的action如下: view代码如下: 单击按钮时,执行如下动作 当点击按钮时,我们发现,虽然后台action验证失败,但 还是执行返回true, ...

  6. git diff 的简单使用(比较版本区别)

    假如我们修改viewMail.vue 文件(部分代码) 从 //根据ID获取详情 getById () { let that = this; this.viewMailModal = true; th ...

  7. xcode 把项目代码提交到远程SVN服务器

    环境 xcode 7  Mac air xcode默认支持GIT源码管理工具,但现在想把代码提交到已有到SVN服务器上,步骤如下: 1,在safari中打开svn链接地址,信任证书,输入用户名密码 , ...

  8. 如何检测浏览器是否能用ActiveX

    var xhr=false; function CreateXHR(){ try{ //检查能否用activexobject xhr=new ActiveXObject("msxml2.XM ...

  9. 不怕你配置不会,就怕你看的资料不对!MIM 与 SharePoint 同步完全配置指南。

    为了更好的同步 User Profile,在 SharePoint 2010 中首次引入了 FIM (ForeFront Identity Manager) 用于编辑 User Profile 的同期 ...

  10. XY//电容

    X,Y电容都是安规电容,火线零线间的是X电容,火线与地间的是Y电容.它们用在电源滤波器里,起到电源滤波作用,分别对共模,差模工扰起滤波作用.安规电容是指用于这样的场合,即电容器失效后,不会导致电击,不 ...