码迷,mamicode.com
首页 > 其他好文 > 详细

QLU Regular Contest 003

时间:2021-02-09 12:18:08      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ima   rac   sig   mamicode   tor   添加   自动   法则   tac   

B.Youmu with the determinant

没什么好说的,求行列式的值。

\(2\le n\le10\)

数据范围很小,直接代数余子式递归求结果即可。

/**
       爆ぜろリアル!弾けろシナプス!パニッシュメント?ディス?ワールド!     
                                                                          
                         ‘;!!!:`                                        
                     .;%%%%$$$$%%%;.                                    
                   .;$%;.         :%;.                                  
                  `||`              :!.                                 
                 .!:                 ::                                 
                 :;                  .`.                                
                 ‘`                   ..                                
                 ``                   .                                 
                  ..                 ..                                 
                                     ..                                 
                         `;||!:‘;|%$$$%%%$$%|;‘.                        
                     ‘|%%%%%%%%%%%%%%%%%%%%%%%%%%%%|:.                  
                   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$|:               
                .:!%%%%%%%%%%|!|%%%%$$&$$$%%%%%%%%%%%%%%%%|‘   `:‘.     
               ‘!|%%%%%||%%%%%%%%%%%$&&&$%%%%%$$$%%%%%%%%%%%|‘‘:‘:‘.    
             `|%%%%%%%%%%%%%$%%%%%%%$&&&&$$%%%$$$%%%%%%%%%%%%|;:::‘::‘:`
            :%%%%%%$$%%%$$%%$%%%%%%%$&&&&&$$%%|%$%%%|!|%%%%%$!‘::::;|!:‘.
          .;$%%%%%$$%%%$$%%$%%%%%%%%$&&&&&$$$%%$$$%%%!!%$%%%%!::!%%%%|;‘.
         .;%$%%%$$$%%%$$%%||%$$%%%%$$&&&&&&$$%%$$%%%%%%%$&&&$%$$$$%%%%|:.
         ;%%%%%$$$%%$&$%%!:!$$$%%%%$&$||&&&&$$%$$$%%%%%%$$$%%%%$$$$%%%|‘
        :%%$%%$$$$%$&&$%!`‘|$&$%%%%$&|`.!&&&&$%$$$%%%%%%%$%%%%%%$$$$%%%;
       `!%|%%%$&$%%$&$$|‘.‘|&&$%%%%$%|!‘.:$&&&$$$$%%%%%%%%%%%%%%$$$$%%%|`
       ;%‘:%%$&&$%$&|!|‘.`:|&&$%%%$$|‘‘‘``‘%&&&$$$%%%%%%%%%%%%%%$&&$%%%%:
      `;‘ ;%%$&$%%$%;;:   .:!%$%%%$|`  ..  .!&&&$$$%%$%%%$%$$%$$%$&$%%%$;
      ‘‘ .!%$&&$$%$;`:‘      `!%%%%:.... ....:$&$$$%$$%%$$$$$%$$%$&$%%%%;
      .. .;%$&&&$%|:.        ...;%|‘..........‘|$%%%$$%%$$&&$%$$%%%$%%%$;
          ;$$&&&$%!`        .`....‘`.... ......`!%%%$$%%$&&&$$&&$!!$%%%$:
          ‘%$&&&&$!`.       .`........``.......`!%%$$$%$&&&&$$&&$;;$%%%%‘
          ‘|$&&&&!``..```.  ........`|@@|‘....`:|%%$$%%$&&&&$$&&$‘:$%%%|`
          `|$&&&&$‘  .``````‘‘‘::`..........``.:%%$&$%|‘`!&&$$&&%‘:%%%%;.
           ;$$&&|;!:`...........  .‘:`....`````!%$&&$%|;‘;&&&%|%%‘;%%%%:
           ‘%$&$:  ...................`‘‘`...`:%%$&$$!`..!&&&$;`:;|%%%!`
            ;$&&%:.....................  .‘:``!%$&&$;...:$&%‘`;‘ ;%%%%: 
            .;$&&&$:..........`‘............`!%$&&&;..‘%&&!     `!%%%:  
             .‘:|&&&|‘‘`..............   ...‘|$&&$||$&&&|`      :|‘``   
                  .!%: `|$%|!:‘`.........`:!%$&&&&&$;‘‘.       `.       
                  .:!%$%||||||%%$$$$$$$$$%$%%$$$%%:.                    
             `!%$%%%%%%%|||||||||||%|||||||%%%%%$%%%%|:                 
          ‘%%%%%%%%%%%%||||||||!!|||||||||||%$$%%%%%%%%$%:              
         :%$$$%%%$%$$%||||||||!;%%||||||||%%%%%%%%%%%%%%%%|‘            
         .;$%%%%$$$$$%%|||||%$$$$$%||||||||%$$%%%%%%%%%%%%%%‘           
          .!%%%%%%$$%%$%%|||||;;%||||||||%$$&&|!%$$%%%$$$$$%;.          
           .!%%%%%%%%%%%%%%$%||%%%%%%%%%%%$&$$;`;%%%%%%%%$$!.           
             :%%%%%%%%%%%%%%||%%%%%%%%%%%$$$%%%%%%%%%%%%%|‘             
                :%%%%%%%%%%$$%%%%%%%%%%%%%%%;`;%%%%%%%|:                
               .;%%%%%%%%%%%%%%%%%%%%%%%%%%%:..:|%%%!.                  
               ‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|;:`                       
               ;$%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%‘                       
              `|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;                       
              .:!%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%$!.                      
              ;!‘;%%%%%%%%%%%%%%%%%%%%%!:`.  `|$%‘                      
             .;%%%%%%%%%%%||%%%%%%%%%|:‘;|%$%%%%%;.                     
             .!%%%%%%%%%%%%$$%%%%%%%%%%%%%%%%%%%%%‘                     
             .!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;.                    
             .;%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%‘                    
              ;%$$%%%%%%%%$$$$%%%%%%%%%%%%%%%%%%%%%‘                    
             `|$&$%%%%%%$%$$$%%%%%%%%%%%%$%%%%%$&%%!`                   
             :%$&$%%||%%%%$$%%%$%%%%%$$!:|%||%%$&$%%!`                  
**/
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algortmphm>
#include <btmpset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif

using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN

const int MAXN = 1e5 + 10;
const double pi = acos(-1.0);
const double eps = 1e-7;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))

#define Dprint(...) printf("%.10f\n", ##__VA_ARGS__)
#define Iprint(...) printf("%d\n", ##__VA_ARGS__)

ll mod = 20210213;
ll check(int p) {
    return p % 2 ? -1 : 1;
}
ll cal(vector<ll> det[], int n) {
    if (n == 1)
        return det[0][0] % mod;

    ll detVal = 0;
    vector<ll> tempdet[n - 1];
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n; j++) {
            tempdet[j - 1].clear();
            for (int k = 0; k < n; k++)
                if (k != i)
                    tempdet[j - 1].push_back(det[j][k]);
        }
        detVal = (detVal + (check(i) * det[0][i] * cal(tempdet, n - 1) % mod + mod) % mod) % mod;
    }
    return detVal % mod;
}
int main() {
    int n;
    cin >> n; 
    vector<ll> det[n];
    for (int i = 0; i < n; i++)
        for (int j = 0, x; j < n; j++) {
            cin >> x;
            det[i].push_back(x);
        }
    cout << cal(det, n);
}

E/F.Youmu with Lianliankan

消消乐,顾名思义,消着快乐,消完了就不快乐了。
一个字符矩阵,每次可以在里面将相同的字母按照一定规则消除。
规则是,连线的拐弯次数不得超过2次。
如所给图1就是合法的

技术图片

图2就是不合法的

技术图片

\(n\leq 20\)显然直接\(bfs\)爆搜即可
搜索方法:

\[在矩阵外添加一圈0,每次bfs只能在0上走,如下\\begin{bmatrix} 0&0&0&0\0&a&a&0\0&b&b&0\0&0&0&0 \end{bmatrix} \1.然后以矩阵内的每一个点为起点s,如果每个点都成为过s,进入5\2.从s开始对每一个点进行bfs\3.循环2,如果此次循环和先前的循环矩阵无变化,那么,回到1;如果全部消除完毕,进入4\4.输出yes,退出程序 5.输出no,退出程序 \]

/**
       爆ぜろリアル!弾けろシナプス!パニッシュメント?ディス?ワールド!     
                                                                          
                         ‘;!!!:`                                        
                     .;%%%%$$$$%%%;.                                    
                   .;$%;.         :%;.                                  
                  `||`              :!.                                 
                 .!:                 ::                                 
                 :;                  .`.                                
                 ‘`                   ..                                
                 ``                   .                                 
                  ..                 ..                                 
                                     ..                                 
                         `;||!:‘;|%$$$%%%$$%|;‘.                        
                     ‘|%%%%%%%%%%%%%%%%%%%%%%%%%%%%|:.                  
                   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$|:               
                .:!%%%%%%%%%%|!|%%%%$$&$$$%%%%%%%%%%%%%%%%|‘   `:‘.     
               ‘!|%%%%%||%%%%%%%%%%%$&&&$%%%%%$$$%%%%%%%%%%%|‘‘:‘:‘.    
             `|%%%%%%%%%%%%%$%%%%%%%$&&&&$$%%%$$$%%%%%%%%%%%%|;:::‘::‘:`
            :%%%%%%$$%%%$$%%$%%%%%%%$&&&&&$$%%|%$%%%|!|%%%%%$!‘::::;|!:‘.
          .;$%%%%%$$%%%$$%%$%%%%%%%%$&&&&&$$$%%$$$%%%!!%$%%%%!::!%%%%|;‘.
         .;%$%%%$$$%%%$$%%||%$$%%%%$$&&&&&&$$%%$$%%%%%%%$&&&$%$$$$%%%%|:.
         ;%%%%%$$$%%$&$%%!:!$$$%%%%$&$||&&&&$$%$$$%%%%%%$$$%%%%$$$$%%%|‘
        :%%$%%$$$$%$&&$%!`‘|$&$%%%%$&|`.!&&&&$%$$$%%%%%%%$%%%%%%$$$$%%%;
       `!%|%%%$&$%%$&$$|‘.‘|&&$%%%%$%|!‘.:$&&&$$$$%%%%%%%%%%%%%%$$$$%%%|`
       ;%‘:%%$&&$%$&|!|‘.`:|&&$%%%$$|‘‘‘``‘%&&&$$$%%%%%%%%%%%%%%$&&$%%%%:
      `;‘ ;%%$&$%%$%;;:   .:!%$%%%$|`  ..  .!&&&$$$%%$%%%$%$$%$$%$&$%%%$;
      ‘‘ .!%$&&$$%$;`:‘      `!%%%%:.... ....:$&$$$%$$%%$$$$$%$$%$&$%%%%;
      .. .;%$&&&$%|:.        ...;%|‘..........‘|$%%%$$%%$$&&$%$$%%%$%%%$;
          ;$$&&&$%!`        .`....‘`.... ......`!%%%$$%%$&&&$$&&$!!$%%%$:
          ‘%$&&&&$!`.       .`........``.......`!%%$$$%$&&&&$$&&$;;$%%%%‘
          ‘|$&&&&!``..```.  ........`|@@|‘....`:|%%$$%%$&&&&$$&&$‘:$%%%|`
          `|$&&&&$‘  .``````‘‘‘::`..........``.:%%$&$%|‘`!&&$$&&%‘:%%%%;.
           ;$$&&|;!:`...........  .‘:`....`````!%$&&$%|;‘;&&&%|%%‘;%%%%:
           ‘%$&$:  ...................`‘‘`...`:%%$&$$!`..!&&&$;`:;|%%%!`
            ;$&&%:.....................  .‘:``!%$&&$;...:$&%‘`;‘ ;%%%%: 
            .;$&&&$:..........`‘............`!%$&&&;..‘%&&!     `!%%%:  
             .‘:|&&&|‘‘`..............   ...‘|$&&$||$&&&|`      :|‘``   
                  .!%: `|$%|!:‘`.........`:!%$&&&&&$;‘‘.       `.       
                  .:!%$%||||||%%$$$$$$$$$%$%%$$$%%:.                    
             `!%$%%%%%%%|||||||||||%|||||||%%%%%$%%%%|:                 
          ‘%%%%%%%%%%%%||||||||!!|||||||||||%$$%%%%%%%%$%:              
         :%$$$%%%$%$$%||||||||!;%%||||||||%%%%%%%%%%%%%%%%|‘            
         .;$%%%%$$$$$%%|||||%$$$$$%||||||||%$$%%%%%%%%%%%%%%‘           
          .!%%%%%%$$%%$%%|||||;;%||||||||%$$&&|!%$$%%%$$$$$%;.          
           .!%%%%%%%%%%%%%%$%||%%%%%%%%%%%$&$$;`;%%%%%%%%$$!.           
             :%%%%%%%%%%%%%%||%%%%%%%%%%%$$$%%%%%%%%%%%%%|‘             
                :%%%%%%%%%%$$%%%%%%%%%%%%%%%;`;%%%%%%%|:                
               .;%%%%%%%%%%%%%%%%%%%%%%%%%%%:..:|%%%!.                  
               ‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|;:`                       
               ;$%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%‘                       
              `|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;                       
              .:!%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%$!.                      
              ;!‘;%%%%%%%%%%%%%%%%%%%%%!:`.  `|$%‘                      
             .;%%%%%%%%%%%||%%%%%%%%%|:‘;|%$%%%%%;.                     
             .!%%%%%%%%%%%%$$%%%%%%%%%%%%%%%%%%%%%‘                     
             .!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;.                    
             .;%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%‘                    
              ;%$$%%%%%%%%$$$$%%%%%%%%%%%%%%%%%%%%%‘                    
             `|$&$%%%%%%$%$$$%%%%%%%%%%%%$%%%%%$&%%!`                   
             :%$&$%%||%%%%$$%%%$%%%%%$$!:|%||%%$&$%%!`                  
**/
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algortmphm>
#include <btmpset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif

using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN

const int MAXN = 100 + 10;
const double pi = acos(-1.0);
const double eps = 1e-7;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))

#define Dprint(...) printf("%.10f\n", ##__VA_ARGS__)
#define Iprint(...) printf("%d\n", ##__VA_ARGS__)

char s[MAXN][MAXN], s2[MAXN][MAXN];
bool vis[MAXN][MAXN];
vector<pair<pair<int, int>, pair<int, int>>> v;
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, 1, -1};
struct vec {
    int x, y, f, p;
};
int n;
void bfs(int x, int y) {
    memset(vis, 0, sizeof(vis));
    queue<vec> q;
    q.push(vec{x, y, 0, -1});
    bool flag = vis[x][y] = 1;
    while (!q.empty() && flag) {
        vec tmp = q.front();
        q.pop();
        for (int i = 0, ix, iy; i < 4; i++) {
            ix = tmp.x + dx[i], iy = tmp.y + dy[i];
            if (ix >= 0 && ix <= n + 1 && iy >= 0 && iy <= n + 1 && !vis[ix][iy])
                if (s2[ix][iy] == 0) {
                    vis[ix][iy] = 1;
                    if (i == tmp.p)
                        q.push(vec{ix, iy, tmp.f, tmp.p});
                    else if (tmp.f < 3)
                        q.push(vec{ix, iy, tmp.f + 1, i});
                } else if (s2[ix][iy] == s2[x][y])
                    if (tmp.f + (i != tmp.p) <= 3) {
                        v.push_back(make_pair(make_pair(x, y), make_pair(ix, iy)));
                        s2[x][y] = s2[ix][iy] = flag = 0;
                        break;
                    }
        }
    }
}
bool solve(int x, int y) {
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            s2[i][j] = s[i][j];
    v.clear();
    while (1) {
        int lpos = v.size();
        for (int i = y; i <= n; i++)
            if (s2[x][i])
                bfs(x, i);
        for (int i = x + 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                if (s2[i][j])
                    bfs(i, j);
        for (int i = 1; i < x; i++)
            for (int j = 1; j <= n; j++)
                if (s2[i][j])
                    bfs(i, j);
        for (int i = 1; i < y; i++)
            if (s2[x][i])
                bfs(x, i);
        if (lpos == v.size())
            break;
    }
    if (v.size() * 2 == n * n) {
        cout << "YES" << endl;
        for (auto it : v)
            printf("%d %d %d %d\n", it.first.first, it.first.second, it.second.first, it.second.second);
        return 1;
    } else
        return 0;
}
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%s", s[i] + 1);

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (s[i][j])
                if (solve(i, j))
                    exit(0);
    cout << "NO" << endl;
}
``

H. Youmu with Master spark

解法一

\[用高数知识求解:\\int_{0}^{1} t^2|e^{2t}-x|\, dx \分界点时x=e^{2t} \那么就可以拆为: \int_{0}^{\frac{1}{2}\ln{x}} t^2(e^{2t}-x)\, dx-\int_{\frac{1}{2}\ln{x}}^{1} t^2(e^{2t}-x)\, dx \求原函数,使用分部积分,然后整理化简可以得到 \frac{1}{12}x\ln^3{x}-\frac{1}{3}x+\frac{1}{4}+\frac{1}{4}e^2-\frac{1}{4}x\ln^2{x}+\frac{1}{2}x\ln{x}-\frac{1}{2}x ①\我们这里注意,0\leq \frac{1}{2}\ln{x} \leq 1,也就意味着,1\leq x\leq e^2 \所以我们将x=e^2代入,得到\frac{1}{3}x-\frac{1}{4}e^2+\frac{1}{4}②\整理最后我们的式子就变成了\f(x) = \begin{cases} \frac{1}{12}x\ln^3{x}-\frac{1}{3}x+\frac{1}{4}+\frac{1}{4}e^2-\frac{1}{4}x\ln^2{x}+\frac{1}{2}x\ln{x}-\frac{1}{2}x , &1 \leq x\leq e^2 \\frac{1}{3}x-\frac{1}{4}e^2+\frac{1}{4} , & x>e^2 \end{cases} \\然后对于n\geq e^2的,我们观察这个式子,可以知道,这是个等差数列求和, S=\frac{(n+8)(n-8+1)}{2}\然后答案就很显然了,至于超时,我们需要把前7项存到dp[i]内.\对于8到n项的答案 就是dp[7]+\frac{(n+8)(n-8+1)}{2} \]

/**
       爆ぜろリアル!弾けろシナプス!パニッシュメント?ディス?ワールド!     
                                                                          
                         ‘;!!!:`                                        
                     .;%%%%$$$$%%%;.                                    
                   .;$%;.         :%;.                                  
                  `||`              :!.                                 
                 .!:                 ::                                 
                 :;                  .`.                                
                 ‘`                   ..                                
                 ``                   .                                 
                  ..                 ..                                 
                                     ..                                 
                         `;||!:‘;|%$$$%%%$$%|;‘.                        
                     ‘|%%%%%%%%%%%%%%%%%%%%%%%%%%%%|:.                  
                   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$|:               
                .:!%%%%%%%%%%|!|%%%%$$&$$$%%%%%%%%%%%%%%%%|‘   `:‘.     
               ‘!|%%%%%||%%%%%%%%%%%$&&&$%%%%%$$$%%%%%%%%%%%|‘‘:‘:‘.    
             `|%%%%%%%%%%%%%$%%%%%%%$&&&&$$%%%$$$%%%%%%%%%%%%|;:::‘::‘:`
            :%%%%%%$$%%%$$%%$%%%%%%%$&&&&&$$%%|%$%%%|!|%%%%%$!‘::::;|!:‘.
          .;$%%%%%$$%%%$$%%$%%%%%%%%$&&&&&$$$%%$$$%%%!!%$%%%%!::!%%%%|;‘.
         .;%$%%%$$$%%%$$%%||%$$%%%%$$&&&&&&$$%%$$%%%%%%%$&&&$%$$$$%%%%|:.
         ;%%%%%$$$%%$&$%%!:!$$$%%%%$&$||&&&&$$%$$$%%%%%%$$$%%%%$$$$%%%|‘
        :%%$%%$$$$%$&&$%!`‘|$&$%%%%$&|`.!&&&&$%$$$%%%%%%%$%%%%%%$$$$%%%;
       `!%|%%%$&$%%$&$$|‘.‘|&&$%%%%$%|!‘.:$&&&$$$$%%%%%%%%%%%%%%$$$$%%%|`
       ;%‘:%%$&&$%$&|!|‘.`:|&&$%%%$$|‘‘‘``‘%&&&$$$%%%%%%%%%%%%%%$&&$%%%%:
      `;‘ ;%%$&$%%$%;;:   .:!%$%%%$|`  ..  .!&&&$$$%%$%%%$%$$%$$%$&$%%%$;
      ‘‘ .!%$&&$$%$;`:‘      `!%%%%:.... ....:$&$$$%$$%%$$$$$%$$%$&$%%%%;
      .. .;%$&&&$%|:.        ...;%|‘..........‘|$%%%$$%%$$&&$%$$%%%$%%%$;
          ;$$&&&$%!`        .`....‘`.... ......`!%%%$$%%$&&&$$&&$!!$%%%$:
          ‘%$&&&&$!`.       .`........``.......`!%%$$$%$&&&&$$&&$;;$%%%%‘
          ‘|$&&&&!``..```.  ........`|@@|‘....`:|%%$$%%$&&&&$$&&$‘:$%%%|`
          `|$&&&&$‘  .``````‘‘‘::`..........``.:%%$&$%|‘`!&&$$&&%‘:%%%%;.
           ;$$&&|;!:`...........  .‘:`....`````!%$&&$%|;‘;&&&%|%%‘;%%%%:
           ‘%$&$:  ...................`‘‘`...`:%%$&$$!`..!&&&$;`:;|%%%!`
            ;$&&%:.....................  .‘:``!%$&&$;...:$&%‘`;‘ ;%%%%: 
            .;$&&&$:..........`‘............`!%$&&&;..‘%&&!     `!%%%:  
             .‘:|&&&|‘‘`..............   ...‘|$&&$||$&&&|`      :|‘``   
                  .!%: `|$%|!:‘`.........`:!%$&&&&&$;‘‘.       `.       
                  .:!%$%||||||%%$$$$$$$$$%$%%$$$%%:.                    
             `!%$%%%%%%%|||||||||||%|||||||%%%%%$%%%%|:                 
          ‘%%%%%%%%%%%%||||||||!!|||||||||||%$$%%%%%%%%$%:              
         :%$$$%%%$%$$%||||||||!;%%||||||||%%%%%%%%%%%%%%%%|‘            
         .;$%%%%$$$$$%%|||||%$$$$$%||||||||%$$%%%%%%%%%%%%%%‘           
          .!%%%%%%$$%%$%%|||||;;%||||||||%$$&&|!%$$%%%$$$$$%;.          
           .!%%%%%%%%%%%%%%$%||%%%%%%%%%%%$&$$;`;%%%%%%%%$$!.           
             :%%%%%%%%%%%%%%||%%%%%%%%%%%$$$%%%%%%%%%%%%%|‘             
                :%%%%%%%%%%$$%%%%%%%%%%%%%%%;`;%%%%%%%|:                
               .;%%%%%%%%%%%%%%%%%%%%%%%%%%%:..:|%%%!.                  
               ‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|;:`                       
               ;$%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%‘                       
              `|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;                       
              .:!%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%$!.                      
              ;!‘;%%%%%%%%%%%%%%%%%%%%%!:`.  `|$%‘                      
             .;%%%%%%%%%%%||%%%%%%%%%|:‘;|%$%%%%%;.                     
             .!%%%%%%%%%%%%$$%%%%%%%%%%%%%%%%%%%%%‘                     
             .!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;.                    
             .;%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%‘                    
              ;%$$%%%%%%%%$$$$%%%%%%%%%%%%%%%%%%%%%‘                    
             `|$&$%%%%%%$%$$$%%%%%%%%%%%%$%%%%%$&%%!`                   
             :%$&$%%||%%%%$$%%%$%%%%%$$!:|%||%%$&$%%!`                  
**/
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algortmphm>
#include <btmpset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif

using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN

const int MAXN = 1e5 + 10;
const double pi = acos(-1.0);
const double eps = 1e-7;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))

#define Dprint(...) printf("%.10f\n", ##__VA_ARGS__)
#define Iprint(...) printf("%d\n", ##__VA_ARGS__)

double f2(int x) {
    return x * pow(log(x), 3) / 12.0 - x / 3.0 + 0.25 + 0.25 * exp(2) - x * pow(log(x), 2) * 0.25 + 0.5 * x * log(x) - 0.5 * x;
}
double sum(int x) {
    return f2(x);
}
double dp[8];
int main() {
    int t;
    cin >> t;
    for (int i = 1; i <= 7; i++)
        dp[i] = dp[i - 1] + sum(i);
    Dprint(dp[7] + sum(8));
    while (t--) {
        int n;
        scanf("%d", &n);
        double ans = 0;
        if (n >= 8)
            ans = dp[7] + (n - 8 + 1) * ((1 - exp(2)) * 0.25 + (n + 8) / 6.0);
        else
            ans = dp[n];
        Dprint(ans);
    }
}

解法二

\[用辛普森积分法模板求解.\辛普森积分法,顾名思义,这就是个求积分的.\它的基本框架如下所示 \]

double fun(double x) //原积分函数
{
    return x;
}
double simpson(double l, double r) //辛普森法则
{
    double mid = (l + r) / 2.0;
    return (fun(l) + fun(r) + 4.0 * fun(mid)) * (r - l) / 6.0;
}
double asr(double l, double r, double eps, double ans) {//自适应自动控制区间分割的大小
    double mid = (l + r) / 2;
    double l_ = simpson(l, mid), r_ = simpson(mid, r);
    if (fabs(l_ + r_ - ans) <= 15 * eps)
        return l_ + r_ + (l_ + r_ - ans) / 15;
    return asr(l, mid, eps / 2, l_) + asr(mid, r, eps / 2, r_);
}
inline double _asr(double l, double r, double eps) {//函数进入口
    return asr(l, r, eps, simpson(l, r));
}

\(有了板子,我们就可以直接往里套了,把模板改一改就是答案了\)

/**
       爆ぜろリアル!弾けろシナプス!パニッシュメント?ディス?ワールド!     
                                                                          
                         ‘;!!!:`                                        
                     .;%%%%$$$$%%%;.                                    
                   .;$%;.         :%;.                                  
                  `||`              :!.                                 
                 .!:                 ::                                 
                 :;                  .`.                                
                 ‘`                   ..                                
                 ``                   .                                 
                  ..                 ..                                 
                                     ..                                 
                         `;||!:‘;|%$$$%%%$$%|;‘.                        
                     ‘|%%%%%%%%%%%%%%%%%%%%%%%%%%%%|:.                  
                   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$|:               
                .:!%%%%%%%%%%|!|%%%%$$&$$$%%%%%%%%%%%%%%%%|‘   `:‘.     
               ‘!|%%%%%||%%%%%%%%%%%$&&&$%%%%%$$$%%%%%%%%%%%|‘‘:‘:‘.    
             `|%%%%%%%%%%%%%$%%%%%%%$&&&&$$%%%$$$%%%%%%%%%%%%|;:::‘::‘:`
            :%%%%%%$$%%%$$%%$%%%%%%%$&&&&&$$%%|%$%%%|!|%%%%%$!‘::::;|!:‘.
          .;$%%%%%$$%%%$$%%$%%%%%%%%$&&&&&$$$%%$$$%%%!!%$%%%%!::!%%%%|;‘.
         .;%$%%%$$$%%%$$%%||%$$%%%%$$&&&&&&$$%%$$%%%%%%%$&&&$%$$$$%%%%|:.
         ;%%%%%$$$%%$&$%%!:!$$$%%%%$&$||&&&&$$%$$$%%%%%%$$$%%%%$$$$%%%|‘
        :%%$%%$$$$%$&&$%!`‘|$&$%%%%$&|`.!&&&&$%$$$%%%%%%%$%%%%%%$$$$%%%;
       `!%|%%%$&$%%$&$$|‘.‘|&&$%%%%$%|!‘.:$&&&$$$$%%%%%%%%%%%%%%$$$$%%%|`
       ;%‘:%%$&&$%$&|!|‘.`:|&&$%%%$$|‘‘‘``‘%&&&$$$%%%%%%%%%%%%%%$&&$%%%%:
      `;‘ ;%%$&$%%$%;;:   .:!%$%%%$|`  ..  .!&&&$$$%%$%%%$%$$%$$%$&$%%%$;
      ‘‘ .!%$&&$$%$;`:‘      `!%%%%:.... ....:$&$$$%$$%%$$$$$%$$%$&$%%%%;
      .. .;%$&&&$%|:.        ...;%|‘..........‘|$%%%$$%%$$&&$%$$%%%$%%%$;
          ;$$&&&$%!`        .`....‘`.... ......`!%%%$$%%$&&&$$&&$!!$%%%$:
          ‘%$&&&&$!`.       .`........``.......`!%%$$$%$&&&&$$&&$;;$%%%%‘
          ‘|$&&&&!``..```.  ........`|@@|‘....`:|%%$$%%$&&&&$$&&$‘:$%%%|`
          `|$&&&&$‘  .``````‘‘‘::`..........``.:%%$&$%|‘`!&&$$&&%‘:%%%%;.
           ;$$&&|;!:`...........  .‘:`....`````!%$&&$%|;‘;&&&%|%%‘;%%%%:
           ‘%$&$:  ...................`‘‘`...`:%%$&$$!`..!&&&$;`:;|%%%!`
            ;$&&%:.....................  .‘:``!%$&&$;...:$&%‘`;‘ ;%%%%: 
            .;$&&&$:..........`‘............`!%$&&&;..‘%&&!     `!%%%:  
             .‘:|&&&|‘‘`..............   ...‘|$&&$||$&&&|`      :|‘``   
                  .!%: `|$%|!:‘`.........`:!%$&&&&&$;‘‘.       `.       
                  .:!%$%||||||%%$$$$$$$$$%$%%$$$%%:.                    
             `!%$%%%%%%%|||||||||||%|||||||%%%%%$%%%%|:                 
          ‘%%%%%%%%%%%%||||||||!!|||||||||||%$$%%%%%%%%$%:              
         :%$$$%%%$%$$%||||||||!;%%||||||||%%%%%%%%%%%%%%%%|‘            
         .;$%%%%$$$$$%%|||||%$$$$$%||||||||%$$%%%%%%%%%%%%%%‘           
          .!%%%%%%$$%%$%%|||||;;%||||||||%$$&&|!%$$%%%$$$$$%;.          
           .!%%%%%%%%%%%%%%$%||%%%%%%%%%%%$&$$;`;%%%%%%%%$$!.           
             :%%%%%%%%%%%%%%||%%%%%%%%%%%$$$%%%%%%%%%%%%%|‘             
                :%%%%%%%%%%$$%%%%%%%%%%%%%%%;`;%%%%%%%|:                
               .;%%%%%%%%%%%%%%%%%%%%%%%%%%%:..:|%%%!.                  
               ‘%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|;:`                       
               ;$%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%‘                       
              `|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;                       
              .:!%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%$!.                      
              ;!‘;%%%%%%%%%%%%%%%%%%%%%!:`.  `|$%‘                      
             .;%%%%%%%%%%%||%%%%%%%%%|:‘;|%$%%%%%;.                     
             .!%%%%%%%%%%%%$$%%%%%%%%%%%%%%%%%%%%%‘                     
             .!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;.                    
             .;%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%‘                    
              ;%$$%%%%%%%%$$$$%%%%%%%%%%%%%%%%%%%%%‘                    
             `|$&$%%%%%%$%$$$%%%%%%%%%%%%$%%%%%$&%%!`                   
             :%$&$%%||%%%%$$%%%$%%%%%$$!:|%||%%$&$%%!`                  
**/
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algortmphm>
#include <btmpset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif

using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN

const int MAXN = 1e5 + 10;
const double pi = acos(-1.0);
const double eps = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))

#define Dprint(...) printf("%.10f\n", ##__VA_ARGS__)
#define Iprint(...) printf("%d\n", ##__VA_ARGS__)

/**
 * 以下
 * 皆为
 * 辛普森函数
 * */
double fun(double t, double x) //原积分函数
{
    return t * t * fabs(exp(t + t) - x);
}
double simpson(double l, double r, double x) //辛普森法则
{
    double mid = (l + r) / 2.0;
    return (fun(l, x) + fun(r, x) + 4.0 * fun(mid, x)) * (r - l) / 6.0;
}
double asr(double l, double r, double eps, double ans, double x) {
    double mid = (l + r) / 2;
    double l_ = simpson(l, mid, x), r_ = simpson(mid, r, x);
    if (fabs(l_ + r_ - ans) <= 15 * eps)
        return l_ + r_ + (l_ + r_ - ans) / 15;
    return asr(l, mid, eps / 2, l_, x) + asr(mid, r, eps / 2, r_, x);
}
inline double _asr(double l, double r, double eps, double x) {
    return asr(l, r, eps, simpson(l, r, x), x);
}
double dp[8];
int main() {
    int t;
    cin >> t;
    // dp[1] = -1.0 / 3.0 + exp(2) * 0.25 - 0.25;
    for (int i = 1; i <= 7; i++)
        dp[i] = dp[i - 1] + _asr(0, 1, eps, i);
    while (t--) {
        int n;
        // cin >> n;
        scanf("%d", &n);
        double ans = 0;
        if (n >= 8)
            ans = dp[7] + (n - 8 + 1) * ((1 - exp(2)) * 0.25 + (n + 8) / 6.0);
        else
            ans = dp[n];
        Dprint(ans);
    }
}

\[关于辛普森公式的简单推导\辛普森公式就是在积分区间[a,b]上去找三个点a,b和m=\frac{a+b}{2}\计算其原函数在此处的值,然后用抛物线来拟合原函数。\我们设f(x)是原函数,g(x)=Ax^2+Bx+C 那么积分\\int_{a}^{b} f(x)\,dx \simeq \int_{a}^{b}Ax^2+Bx+C \=\frac{b-a}{6}(Aa^2+Ba+C+Ab^2+Bb+C+4A(\frac{a+b}{2})^2+4B(\frac{a+b}{2})+4C)\\= \frac{b-a}{6}(f(a)+f(b)+4f(\frac{a+b}{2}))\简单了解就好 \]

QLU Regular Contest 003

标签:ima   rac   sig   mamicode   tor   添加   自动   法则   tac   

原文地址:https://www.cnblogs.com/CrossAutomaton/p/14390028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!