Summer N Tianle [articles] game --2019 cattle off summer school and more training camp (first)

The long-awaitedThe highlight of the summer finally be fired the first shot ... it was first expected to be suspended or beaten up ... full field of math problems and their chicken dishes Crazy English domination. Replenishment words,estimateCan only do what it - a solution to a problem can not be pushed out of standard process have not read the siskin.

A B C D E F G H I J

For now fix problems may only do C, H ...It may also be the case

Contest Address: https://ac.nowcoder.com/acm/contest/881#question

【A】 Equivalent Prefixes

Two arrays are defined "equal" concept: \ (take any sub-range within [1, m] interval [l, r] are located to meet the minimum range position (subscript) the same \) . Then given two arrays, the maximum value of m ask is how much.

Read the whole question his teammates before the two rounds played wa ... read all questions wrong, then get out behind how the original idea. Mate completely pushed back queue may be rewritten over a monotone. Then explain the problem of Cartesian tree is confused, so ... monotone queue rewrite it again. The following is the supplement after the game title Code:

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

const int maxn = 1e5+5;

int a[maxn], b[maxn];

int main() {
    int n;
    while(~scanf("%d", &n)) {
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
        }
        for(int i = 1; i <= n; i++) {
            scanf("%d", &b[i]);
        }
        int flag = 1;
        stack<int> sa, sb;
        for(int i = 1; i <= n; i++) {
            while(!sa.empty() && a[i] < a[sa.top()]) {
                sa.pop();
            }
            sa.push(i);
            while(!sb.empty() && b[i] < b[sb.top()]) {
                sb.pop();
            }
            sb.push(i); 
            if(sa.size() != sb.size()) {
                printf("%d\n", i-1);
                flag = 0;
                break;
            }
        }
        if(flag == 1) {
            printf("%d\n", n);
        }
    }
    return 0;
}

【B】 Integration

Known: \ (\ int ^ {\ infty} _ {0} \ {FRAC. 1. 1} {2} + DX = X ^ \ FRAC {\ PI} {2} \) . Then you give the number n, seeking:
\ [\ FRAC. 1 {{} \} PI \ int ^ {\ infty} _ {0} \ {FRAC. 1} {\ Prod _ ^ {n} = {I}. 1 ( a_i ^ 2 + x ^ 2) } dx \]

Then the resulting fraction is probably need to \ (\ frac {p} { q} \) form into \ (^ P * Q {-} MOD. 1 (1E + ^. 9. 7) \) .

60+ high number of chicken dishes drifting, push it out, do not blame me for it ...

令:
\[c_i = \frac{1}{\prod_{j\neq i}(a_j^2 - a_i^2)}\]

则:
\[\frac{1}{\prod(a_i^2 + x^2)} = \sum \frac{c_i}{a_i^2+x^2}\]

而:
\[\int^{\infty}_{0}\frac{c_i}{a_i^2+x^2}dx = \frac{c_i}{2a_i}\pi\]

Long live the solution to a problem

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
 
const int maxn = 1e3+5;
 
ll _c[maxn];
ll a[maxn];
 
ll q_pow(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b & 1) {
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
 
int main() {
    int n;
    while(~scanf("%d", &n)) {
        ll ans = 0;
        for(int i = 0; i <= n; i++) {
            _c[i] = 1;
        }
        for(int i = 1; i <= n; i++) {
            scanf("%lld", &a[i]);
        }
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                if(i == j) {
                    continue;
                }
                _c[i] = _c[i] * (a[j]*a[j]%mod - a[i]*a[i]%mod + mod) % mod;
            }
            _c[i] = _c[i] * 2ll * a[i] % mod;
            ans = (ans + q_pow(_c[i], mod-2)) % mod;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

【E】 ABBA

Has a length \ (2 (n + m) \) string, its sequences can be split into: "n th AB, m a BA." Q. There are many kinds of sort.

emmm ... may still dp brush a little, but did not think think that dp is based on the number of A, B is transferred.

\ (dp [i] [j ] represents the i-th prefix A, j th B \) and then run \ (n ^ 2 \) each time by A, B is inserted transferred, troublesome to deal with border.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
 
const int maxn = 2e3+5;
 
int n, m;
int dp[maxn][maxn];     // dp[i][j] 表示前缀有 i 个 A、 j 个 B
 
int main() {
    while(~scanf("%d%d", &n, &m)) {
        int l = n+m;
        for(int i = 0; i <= l+1; i++) {
            for(int j = 0; j <= l+1; j++) {
                dp[i][j] = 0;
            }
        }
        dp[0][0] = 1;
        for(int i = 0; i <= l; i++) {
            for(int j = 0; j <= l; j++) {
                if(i <= n-1 || i-n <= min(j, m)-1) {
                    // 因为 i 从 0 开始,所以最大只能到 n-1;后边也同理
                    dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
                }
                if(j <= m-1 || j-m <= min(i, n)-1) {
                    dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % mod;
                }
            }
        }
        printf("%d\n", dp[l][l]);
    }
    return 0;
}

【F】 Random Point in Triangle

To three o'clock, there is now a random point P falls within a triangle, the triangle given expected value Q \ (E = max \ of S_ {} {the PAB, the PBC of S_ {}, the PCA of S_ {} \} \) , the answer to the output multiplied by 36.

The very essence of the ride gave 36 ... because the data is too large, it can not directly use Helen formula (I anyway WA a), so I used longlong and cut and fill method to eliminate errors. Is then calculated (statistical random number and then guess too) find the answer is the area of triangle \ (\ FRAC. 11} {2} {\) .Do not ask why, and asked that his teammates do.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
 
const int maxn = 5;
 
struct node {
    ll x, y;
    bool operator < (const node &a) const {
        return x < a.x;
    }
}p[maxn];
 
int main() {
    ll x1, x2, x3, y1, y2, y3;
    while(~scanf("%lld%lld%lld%lld%lld%lld", &p[1].x, &p[1].y, &p[2].x, &p[2].y, &p[3].x, &p[3].y)) {
        for(int i = 1; i <= 3; i++) {
            p[i].x += 100000000;
            p[i].y += 100000000;
        }
        sort(p+1, p+1+3);
        ll m, n;
        ll s1, s2, s3;
        m = p[1].y + p[2].y;
        n = p[2].x - p[1].x;
        s1 = m * n;
        m = p[3].y + p[2].y;
        n = p[3].x - p[2].x;
        s2 = m * n;
        m = p[3].y + p[1].y;
        n = p[3].x - p[1].x;
        s3 = m * n;    
 
        ll ans = abs(s1 + s2 - s3);
        printf("%lld\n", ans*11ll);  
    }
    return 0;
}

【J】 Fraction Comparision

Given two points, let you determine which greater.

Obviously if ... direct division accuracy is not enough for it, and then think of using \ (\ _ \ _ int128 \ ) a. Then ranks no one will read, and then read the first longlong, when calculated in strong turn on the line.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
 
 
 
int main() {
    ll x, a, y, b;
    while(~scanf("%lld%lld%lld%lld", &x, &a, &y, &b)) {
        __int128 ans1 = (__int128)x*b, ans2 = (__int128)y*a;
        if(ans1 > ans2) {
            printf(">\n");
        }
        else if(ans1 == ans2){
            printf("=\n");
        }
        else {
            printf("<\n");
        }
    }
    return 0;
}

Believe me, I will make up the title of [ Gugu Gu ].

Guess you like

Origin www.cnblogs.com/Decray/p/11210886.html