2015ACM-ICPC 北京赛区 Problem C. Today Is a Rainy Day
来源:互联网 发布:骑行组队软件 编辑:程序博客网 时间:2024/05/17 16:45
Description
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
1
2
3
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
1
2
3
3
11
大意:给你两个数字串x1,x2。只含有数字1到6
有两种操作1、变换某位数字成为另外一个
2、将某种数字都变换为另一个
问最少操作几次。可以将x2变为x1
我们预处理123456变成abcdef的最小操作2的次数
大概有6^6种情况
然后我们枚举各种变化。将变换后仍和x1不同的位置用操作1改变
然后求出最小值即可
<pre name="code" class="cpp">#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int tmp[11],step[1111111],stp[1111111];int a[111],b[111],c[11],dx[1111111];int tot,ans;int len;queue<int> Q;queue<string> QQ;string x1,x2;inline void solve(){int i,j;for(i=1;i<=tot;i++){for(j=1;j<=len;j++)a[j]=x1[j-1]-'0';for(j=1;j<=6;j++)c[j]=(dx[i]%tmp[j])/tmp[j+1];for(j=1;j<=len;j++)a[j]=c[a[j]];int sum=0;for(j=1;j<=len;j++)if(a[j]!=b[j])sum++;ans=min(ans,sum+stp[i]);}}inline void pre(){int i,j,k;tmp[7]=1;for(i=6;i>=1;i--)tmp[i]=tmp[i+1]*10;memset(step,127/3,sizeof(step));step[123456]=0;Q.push(123456);tot=1;dx[tot]=123456;while(!Q.empty()){int d=Q.front();Q.pop();int tt;for(i=1;i<=6;i++){for(j=1;j<=6;j++){if(i==j)continue;tt=0;for(k=1;k<=6;k++){int t=(d%tmp[k])/tmp[k+1];if(t==i)tt=tt*10+j;elsett=tt*10+t;}if(step[d]+1<step[tt]){step[tt]=step[d]+1;tot++;stp[tot]=step[tt];dx[tot]=tt;Q.push(tt);}}}}}int main(){pre();while(cin>>x2){cin>>x1;len=x1.size();int i;for(i=1;i<=len;i++)b[i]=x2[i-1]-'0';ans=2100000000;solve();printf("%d\n",ans);}return 0;}
0 0
- 2015ACM-ICPC 北京赛区 Problem C. Today Is a Rainy Day
- ICPC 2015 北京 Today Is a Rainy Day
- UVALive7263-Today Is a Rainy Day(2015ICPC北京C题)-模拟+BFS
- hihocoder 1251 Today Is a Rainy Day (2015ICPC北京C题)
- 2015 北京区域赛 Today Is a Rainy Day(暴搜)
- hihocoder 1251 Today Is a Rainy Day 2015北京区域赛C
- hihocoder 1251 Today Is a Rainy Day( 2015北京区域赛C题)
- 2015ACM-ICPC 北京赛区 Problem K. A Math Problem
- 2015北京现场赛UVALive 7263 Today Is a Rainy Day 【bfs】
- 2015ACM-ICPC 北京赛区 Problem A. Xiongnu's Land
- 2015Beijing区域赛(Today Is a Rainy Day-暴搜)
- hiho1251Today Is a Rainy Day【2015北京现场赛】BFS
- hihoCoder 1251 Today Is a Rainy Day(暴力)
- BFS预处理 hihoCoder1251 Today Is a Rainy Day
- UVALive - 7263 Today Is a Rainy Day (BFS预处理)
- UVALive 7263 Today Is a Rainy Day(BFS预处理)
- hihocoder 2015ACM-ICPC 北京赛区 Problem A. Xiongnu's Land
- 2015ACM-ICPC 北京赛区 Problem I. Snake Carpet
- 图解在Matlab中初步操作一下3D图形学算法
- java.util.regex
- [Java] Date 与 String 和 Timestamp 相互转化
- centos apache PHP mkdir: Permission denied problem
- Java 利用Xstream 解析 XML
- 2015ACM-ICPC 北京赛区 Problem C. Today Is a Rainy Day
- Redis源码解析:30发布和订阅
- 1001. 害死人不偿命的(3n+1)猜想 (15)
- 如何提高VS2010的性能,VS2010不再卡
- iOS学习之路1-强制升级
- java框架之访问首页
- Android Service完全解析,关于服务你所需知道的一切(上)
- XStream 常用注释 (去子节点集合)
- 圆点切换 14款不同效果的圆点切换特效