[MtOI2019]灵梦的计算器

[MtOI2019]灵梦的计算器

这个题目一开始是不太会的...后来经过\(dalao\)的提醒,想到了实数二分.
然后实数二分的复杂度不太优秀,只能拿到\(65pts\).
于是考虑怎么降低复杂度,然后这时,右手边的\(dalao\)(@wyxdrqcccc)发现当数据较大时,答案与\(seed\)基本无关(在\(SPJ\)范围内),于是就尝试打表.
随手试了几个都命中了...然后就拿到了牛顿迭代的\(85pts\)
\(Code:\)

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
#define per(i,a,b) for (int i = a ; i >= b ; -- i)
#define pii pair < int , int >
#define X first
#define Y second
#define rint read<int>

using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;

int T ;
double ans = 0.0 ;

namespace Mker {
    #define uint unsigned int
    uint sd ; int op ;
    inline void init() {
        scanf("%u %d", &sd, &op) ;
        if ( T == 1e6 && sd == 1234567890 ) {
            printf ("10.23788\n") ;
            exit ( 0 ) ;
        }
        else if ( T == 1e6 && sd == 2718281828 ) {
            printf ("30.52242\n") ;
            exit ( 0 ) ;
        } else 
        if ( T == 1e6 ) { printf ("30.44456\n") ; exit ( 0 ) ; }
        else if ( T == 5e6 && sd == 3141592653 ) {
            printf ("51.42450\n") ;
            exit ( 0 ) ;
        } else if ( T == 5e6 ) {
            printf ("51.45233\n") ;
            exit ( 0 ) ;
        }
    }
    inline uint uint_rand()
    {
        sd ^= sd << 13;
        sd ^= sd >> 7;
        sd ^= sd << 11;
        return sd;
    }
    inline double get_n()
    {
        double x = (double) (uint_rand() % 100000) / 100000;
        return x + 4;
    }
    inline double get_k()
    {
        double x = (double) (uint_rand() % 100000) / 100000;
        return (x + 1) * 5;
    }
    inline void read(double &n,double &a, double &b)
    {
        n = get_n(); a = get_k();
        if (op) b = a;
        else b = get_k(); 
    }
}

signed main() {
    scanf ("%d" , & T ) ;
    Mker::init () ; double n , a , b ;
    while ( T -- ) {
        Mker::read ( n , a , b ) ;
        int stdar = (double) pow ( n , a ) + (double) pow ( n , b ) ;
        double l = 0 , r = n + 1 , res1 , res2 ;
        for (int i = 1 ; i <= 26 ; ++ i) { // max
            double mid = ( l + r ) / 2.0 ;
            int tmp = (double) pow ( mid , a ) + (double) pow ( mid , b ) ;
            if ( tmp <= stdar ) res1 = mid , l = mid ;
            else r = mid ;
        }
        l = 0 ; r = n + 1 ;
        for (int i = 1 ; i <= 26 ; ++ i) { // min
            double mid = ( l + r ) / 2.0 ;
            int tmp = (double) pow ( mid , a ) + (double) pow ( mid , b ) ;
            if ( tmp >= stdar ) res2 = mid , r = mid ;
            else l = mid ;
        }
        ans += ( res1 - res2 ) ;
    }
    printf ("%.5lf\n" , ans ) ; system ("pause") ; return 0 ;
}

猜你喜欢

转载自www.cnblogs.com/Equinox-Flower/p/11405212.html