UVA 10795 questions about the new Nottingham Tower

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.