hihicoder 1251

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
Sample Output
1
2
3
3

11

 参考http://www.cnblogs.com/Running-Time/p/4978097.html

题意:一串数字变成另一串数字,可以单个数字转变,或者一类数字转变,问最少操作次数
分析:首先一类转换比单个转换优,先枚举找出最优的映射方案,然后将零碎的操作加上。6位6进制表示map映射,比如123456,表示map[1] = 1, map[2] = 2, map[3] = 3...
先预处理出每种方案的的操作数,用BFS+dp写,然后暴力枚举取最小值

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int inf=0x7f7f7f7f;
const int maxn=120;
const int maxm=5e4+5;
char a[maxn],b[maxn];
int dp[maxm],cnt[6],g[6][6];
int idx(int *c)
{
	int tmp=0;
	for(int i=0;i<6;i++)
	tmp=tmp*6+c[i];
	return tmp;
}
void ridx(int x,int *c)
{
	for(int i=5;i>=0;i--)
	{
		c[i]=x%6;
		x=x/6;
	}
}
void bfs()
{
	memset(dp,inf,sizeof(dp));
	int c[6];
	for(int i=0;i<6;i++) c[i]=i;
	int s=idx(c);
	dp[s]=0;
	queue<int>que;
	que.push(s);
	while(!que.empty())
	{
		int u=que.front();
		que.pop();
		ridx(u,c);
		for(int i=0;i<6;i++)
		{
			for(int j=0;j<6;j++)
			{
				int t[6];
				memcpy(t,c,sizeof(t));
				for(int k=0;k<6;k++)
				if(t[k]==i) t[k]=j;
				int v=idx(t);
				if(dp[v]>dp[u]+1)
				{
					dp[v]=dp[u]+1;
					que.push(v);
				}
			}
		}
	}
}
int main()
{
	bfs();
	while(scanf("%s%s",a,b)!=EOF)
	{
		int len=strlen(a);
		memset(cnt,0,sizeof(cnt));
		memset(g,0,sizeof(g));
		for(int i=0;i<len;i++)
		{
			cnt[b[i]-'1']++;
			g[b[i]-'1'][a[i]-'1']++;
		}
		int ans=inf;
		int c[6];
		for(int i=0;i<maxm;i++)
		{
			ridx(i,c);
			int tmp=dp[i];
			for(int j=0;j<6;j++)
				tmp+=(cnt[j]-g[j][c[j]]);
			ans=min(ans,tmp);
		}
		printf("%d\n",ans);
	}
	return 0;
}


基于STM32F407,使用DFS算法实现最短迷宫路径检索,分为三种模式:1.DEBUG模式,2. 训练模式,3. 主程序模式 ,DEBUG模式主要分析bug,测量必要数据,训练模式用于DFS算法训练最短路径,并将最短路径以链表形式存储Flash, 主程序模式从Flash中….zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值