题目链接:http://poj.org/problem?id=1920
题目思路:这道题要倒过来想,就是从一根柱子的状态到达当前状态,这样只要从最大的disk到最小的disk判断是否需要移动就可以了。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<queue>
#include<algorithm>
#include<vector>
#include<stack>
#include<list>
#include<iostream>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
#define Max 110
#define mod 1000000
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a<b?a:b;
}
int two[100100],n,s1,s2,s3;
int flag[100100],num[3],id;
inline void init()
{
int i;
two[0]=1;
for(i=1;i<=100010;i++)
two[i]=(two[i-1]<<1)%mod;
}
int main()
{
int i,j;
init();
while(scanf("%d",&n)!=EOF)
{
scanf("%d%d%d",&num[0],&num[1],&num[2]);
for(i=0;i<3;i++)
for(j=0;j<num[i];j++)
{
scanf("%d",&id);
flag[id]=i;
}
int pos1=flag[n];
int ans=0;
for(i=n;i>=1;i--)
{
if(flag[i]!=pos1)
{
pos1=3-pos1-flag[i];
ans=(ans+two[i-1])%mod;
// printf("%d\n",i);
}
}
printf("%d\n%d\n",flag[n]+1,(ans+mod)%mod);
}
}
分享到:
相关推荐
poj 2771 Guardian of Decency.md
poj 2903 Joy of Mobile Routing.md
poj 3174 Alignment of the Planets.md
业余爱好。所以,算法不一定好,CODING也不一定佳,效率不一定高,只是能通过online judge而已。
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
北大POJ2109-Power of Cryptography 解题报告+AC代码
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
北大POJ2151-Check the difficulty of problems 解题报告+AC代码
POJ2942-Knights of the Round Table 【Tarjan算法】 解题报告+AC代码 http://hi.csdn.net/!s/F3L8HO ================================== 我的POJ所有解题报告:...
北大POJ2739-Sum of Consecutive Prime Numbers 解题报告+AC代码
北大POJ3083-Children of the Candy Corn 解题报告+AC代码
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
poj 3495 Bitwise XOR of Arithmetic Progression.md
poj分类poj分类poj分类poj分类
北大POJ1159-Palindrome 解题报告+AC代码
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj 1353 Color Change of Go Game Pieces.md
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告