Uva 10795 A Different Task
来源:互联网 发布:爽肤水有必要吗 知乎 编辑:程序博客网 时间:2024/05/01 02:37
#include <iostream>#include <cstdio>using namespace std;long long f(int temp[],int i,int aim){if(!i) return 0; /*刚好i就在aim上i就不用移动,否则先把i上面的i-1个移到中转上, 在把i移到aim上(1次),最后把i-1个全部移到aim上:((1<<(i-1))-1)次 */ if(temp[i]==aim) return f(temp,i-1,aim);else return f(temp,i-1,6-temp[i]-aim)+((long long)1<<(i-1)); }int main(){int n,i,k,Case=0,start[65],goal[65];long long ans;while(cin>>n&&n){ Case++;for(i=1;i<=n;i++) cin>>start[i];for(i=1;i<=n;i++) cin>>goal[i];k=n;while(k>0&&start[k]==goal[k]) k--; //找出最大的且在两个局面中位置不同的盘子编号K; if(!k) ans=0;else ans=f(start,k-1,6-start[k]-goal[k])+f(goal,k-1,6-start[k]-goal[k])+1;printf("Case %d: %lld\n",Case,ans);}return 0;}
- Uva 10795 A Different Task
- Uva-10795-A Different Task
- uva 10795 A Different Task
- UVA 10795 A Different Task
- UVA 10795 A Different Task
- Uva 10795 - A Different Task
- UVA - 10795 A Different Task
- Uva 10795 A Different Task
- Uva 10795 A Different Task
- UVA 10795 A Different Task
- UVA - 10795 A Different Task
- UVA 10795 A Different Task
- UVA 10795 A Different Task
- uva 10795 - A Different Task(递归)
- UVA 10795 - A Different Task(递归)
- uva 10795 - A Different Task(递归)
- UVA - 10795 A Different Task 汉诺塔
- Uva 10795 - A Different Task 【模拟】
- FusionCharts参数说明 - 3D柱状图 - Column3D.swf
- 搭建PHP运行环境
- 【杭州赛区现场赛PROBLEM I】阅读理解与模拟-The Power of Xiangqi
- 程代展老师的感悟
- 程代展老师的感悟(前传)
- Uva 10795 A Different Task
- HTMLDOM
- hdu 2070 递归Fibbonacci Number
- Linux GCC常用命令
- linux 下 eclipse 创建avd 出错 failed could not create temp file for system NAND disk
- [MFC]DECLARE_MESSAGE_MAP() 的理解
- 为什么DropDownList的SelectedIndexChanged事件触发不了?
- java序列化
- windows linux jdk 环境配置