1. 程式人生 > >Rikka with Time Complexity(hdu 6424 極限+log)

Rikka with Time Complexity(hdu 6424 極限+log)

題目連結:

Rikka with Time Complexity

 

題意:

定義f(a)=loglog...log(n) (共有a個log),給定2個序列A,B,f(A)=f(A1)^{{f(A2)}^{{...}^{f(An)}}}},f(B)同理。求\lim_{x\rightarrow +\infty }\frac{f(A)}{f(B)},若值為0,輸出-1;若值為+\infty,輸出1;否則,輸出0 。

 

思路:

因為a,b<=3,所以我們對原式上下同求2次log,得:

log(log f(A1)^{{f(A2)}^{f(A3)}})

=log(f(A2)^{f(A3)}*log(f(A1)))

=log(f(A2)^{f(A3)})+log(log(f(A1)))

=f(A3)*log(f(A2))+log(log(f(A1)))

=f(A3)*f(A2+1)+f(A1+2)

先比較f(A3)*f(A2+1)f(A1+2)這兩項的大小,然後大的跟B中的大的比,小的跟B中的小的比即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long ll;

const int MAX = 1e5 + 10;
const int inf = 1e9 + 7;

int x[5],y[5];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        for(int i=1;i<=a;i++){
            scanf("%d",&x[i]);
        }
        for(int i=1;i<=b;i++){
            scanf("%d",&y[i]);
        }
        int amax1,amax2,amax3,amax4;
        if(a==1){
            amax1=x[1]+2;
            amax2=inf;
            amax3=inf;
            amax4=inf;
        }
        else if(a==2){
            amax1=min(x[1]+2,x[2]+1);
            amax2=inf;
            amax3=max(x[1]+2,x[2]+1);
            amax4=inf;
        }
        else{
            if(x[1]+2<x[2]+1&&x[1]+2<x[3]){
                amax1=x[1]+2;
                amax2=inf;
                amax3=min(x[2]+1,x[3]);
                amax4=max(x[2]+1,x[3]);
            }
            else{
                amax1=min(x[2]+1,x[3]);
                amax2=max(x[2]+1,x[3]);
                amax3=x[1]+2;
                amax4=inf;
            }
        }
        int bmax1,bmax2,bmax3,bmax4;
        if(b==1){
            bmax1=y[1]+2;
            bmax2=inf;
            bmax3=inf;
            bmax4=inf;
        }
        else if(b==2){
            bmax1=min(y[1]+2,y[2]+1);
            bmax2=inf;
            bmax3=max(y[1]+2,y[2]+1);
            bmax4=inf;
        }
        else{
            if(y[1]+2<y[2]+1&&y[1]+2<y[3]){
                bmax1=y[1]+2;
                bmax2=inf;
                bmax3=min(y[2]+1,y[3]);
                bmax4=max(y[2]+1,y[3]);
            }
            else{
                bmax1=min(y[2]+1,y[3]);
                bmax2=max(y[2]+1,y[3]);
                bmax3=y[1]+2;
                bmax4=inf;
            }
        }

        if(amax1>bmax1){
            printf("-1\n");
        }
        else if(amax1<bmax1){
            printf("1\n");
        }
        else{
            if(amax2>bmax2){
                printf("-1\n");
            }
            else if(amax2<bmax2){
                printf("1\n");
            }
            else{
                if(amax3>bmax3){
                    printf("-1\n");
                }
                else if(amax3<bmax3){
                    printf("1\n");
                }
                else{
                    if(amax4>bmax4){
                        printf("-1\n");
                    }
                    else if(amax4<bmax4){
                        printf("1\n");
                    }
                    else{
                        printf("0\n");
                    }
                }
            }
        }
    }
    return 0;
}