tag:近似


小数据暴力。

大数据直接比较不好比较,可以 \(\ln\) 一下再比较,就变为求和了。

然后有一个神奇的东西叫斯特林公式。。。(真猜对了/fad)

 

\[\ln (x!)= x\ln x-x+0.5\ln(2\pi x) \]

 


#include<bits/stdc++.h>
using namespace std;
 
template<typename T>
inline void Read(T &n){
    char ch; bool flag=false;
    while(!isdigit(ch=getchar()))if(ch=='-')flag=true;
    for(n=ch^48;isdigit(ch=getchar());n=(n<<1)+(n<<3)+(ch^48));
    if(flag)n=-n;
}
 
typedef long long ll;
 
#define double long double
const double Pi=acos(-1);
const double eps=1e-8;
 
inline double lgjc(int n){return n*log(n)-n+0.5*log(2*n*Pi);}
 
inline char sm(double a, double b){return fabs(a-b)<=eps;}
inline int cmp(double a, double b){return sm(exp(fabs(a-b)),1);}
 
int x[2005], y[2005], tx, ty;
 
int main(){
    int a, b, c, d;
    while(~scanf("%d %d %d %d",&a,&b,&c,&d)){
        d = min(d,c-d); b = min(b,a-b);
        int mx = max(max(a,b),max(c,d));
        if(mx<=20){
            ll A=1, B=1;
            for(int i=1; i<=b; i++) A = A*(a-i+1)/i;
            for(int i=1; i<=d; i++) B = B*(c-i+1)/i;
            if(A<B) puts("0");
            else if(A>B) puts("1");
            else puts("2");
        }
        else if(b<=1000 and d<=1000){
            tx = ty = 0;
            for(int i=1; i<=b; i++) x[++tx] = a-i+1, y[++ty] = i;
            for(int i=1; i<=d; i++) y[++ty] = c-i+1, x[++tx] = i;
            int itx=2, ity=1;
            sort(x+1,x+tx+1);
            sort(y+1,y+ty+1);
            double res = x[1];
            while(itx<=tx and ity<=ty)
                if(res<=1) res *= x[itx], itx++;
                else res /= y[ity], ity++;
            while(itx<=tx){
                res *= x[itx], itx++;
                if(res>1) break;
            }
            while(ity<=ty){
                res /= y[ity], ity++;
                if(res<1) break;
            }
            if(sm(res,1)) puts("2");
            else if(res<1) puts("0");
            else puts("1");
        }
        else{
            double A = lgjc(a)+lgjc(d)+lgjc(c-d);
            double B = lgjc(b)+lgjc(c)+lgjc(a-b);
            if(A<B) puts("0");
            else puts("1");
        }
    }
    return 0;
}