UVA 10795

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int num,n,i,now[61],f[61];
long long Find(int MAX,int target)
{
    if(MAX == 1) return 0;
    int i=MAX-1;
    for(;(i > 0) && (now[i] == 6-now[MAX]-target);i--);
    if(i == 0) return 0;
    return Find(i,6-now[MAX]-target)+(1LL << (i-1));
}
int main()
{
    while(cin>>n && n)
    {
        for(i=1;i <= n;i++)
         cin>>now[i];
        for(i=1;i <= n;i++)
         cin>>f[i];
        for(i=n;i > 0 && f[i] == now[i];i--);
         cout<<"Case "<<++num<<": ";
        if(i == 0)
        {
            cout<<0<<endl;
            continue;
        }
        long long part_one=Find(i,f[i]);
        swap(now,f);
        long long part_two=Find(i,f[i]);
        cout<<part_one+part_two+1<<endl;
    }
}

  白书原题。


你可能感兴趣的:(UVA 10795)