设为首页 加入收藏

TOP

poj1920 Towers of Hanoi
2014-11-23 18:58:21 来源: 作者: 【 】 浏览:7
Tags:poj1920 Towers Hanoi
#include
#include
#include
#include
#include
#include
using namespace std;

int two[100005],pos[100005];

int main()
{
    int n,nn[5],i,j,ans,now,end,mid,a;
    two[0]=1;
    for(i=1;i<=100000;i++)
        two[i]=(two[i-1]*2)%1000000;
    while(~scanf("%d",&n))
    {
        scanf("%d%d%d",&nn[1],&nn[2],&nn[3]);
        for(i=1;i<=3;i++)
        {
            for(j=1;j<=nn[i];j++)
            {
                scanf("%d",&a);
                pos[a]=i;
            }
        }
        ans=0;
        end=now=pos[n];
        printf("%d\n",pos[n]);
        while(n>0)
        {
            if(end!=now)
            {
                ans=(ans+two[n-1])%1000000;
                end=mid;
            }
            n--;
            now=pos[n];
            mid=6-now-end;
        }
        printf("%d\n",ans);
    }
    return 0;
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 4679 String 下一篇UVA 10020 Minimal coverage(贪心..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python 教程 - W3Sch (2025-12-26 12:00:51)
·Python基础教程,Pyt (2025-12-26 12:00:48)
·神仙级python入门教 (2025-12-26 12:00:46)
·“我用Java 8”已成 (2025-12-26 11:19:54)
·下载 IntelliJ IDEA (2025-12-26 11:19:52)