https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= 1736
http://7xjob4.com1.z0.glb.clouddn.com/c2dd6437bf7bef120bf27475f3097822
Test instructions: At least how many steps to move the current state to the specified state of the situation
Idea: First consider the biggest plate, move it to the final position, then the reference situation for one of the pillars is empty, one for the largest, one for the smallest to the second largest. The answer is for the initial situation to move to the reference situation +1+ the final state to the reference situation (reversible). Move one column to another, 2^ (n-1)-1 steps.
1#include <bits/stdc++.h>2 using namespacestd;3 4 intn,sta[ $],fin[ $];5 intcas=1;6 7 Long LongFintP[],intIintFina)8 {9 if(i==0)return 0;Ten if(P[i]==fina)returnF (p,i-1, FINA); One returnF (p,i-1,6-p[i]-fina) + (1ll << (i-1)); A } - - intMain () the { - inti,j; - while(SCANF ("%d", &n)!=eof && n!=0) - { + for(i=1; i<=n;i++) - { +scanf"%d",&sta[i]); A } at for(i=1; i<=n;i++) - { -scanf"%d",&fin[i]); - } - - intk=N; in while(k>=1&& Sta[k]==fin[k]) k--; - to Long Longans=0; + if(k>0) - { theAns=f (sta,k-1,6-sta[k]-fin[k]) +f (fin,k-1,6-STA[K]-FIN[K]) +1; * } $printf"Case %d:%lld\n", cas++, ans);Panax Notoginseng } - return 0; the}View Code
UVA 10795 questions about the new Nottingham Tower