Summer vacation N Tianle [Competition] - Bullock Summer Multi-school Training Camp 2019 (First)

Posted by thoand on Thu, 18 Jul 2019 18:44:07 +0200

The long-awaited highlight of the summer vacation was finally the first shot (... the first unexpected one was hoisted (... madly dominated by a lot of math questions and my own chicken English).To supplement the question, it is estimated that we can only do our best - a question can not be solved and the scale can not be understood.

A B C D E F G H I J

For the moment, it may only be C, H... or that's it.

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

[A] Equivalent Prefixes

Defines the concept of "equality" between two arrays: \([1, m], within the range of [1, m], any subinterval [l, r] satisfies the position where the minimum value of the interval is located (subscript) is the same\).Given two arrays, ask what is the maximum value of M.

Reading the title put the teammates on full show.. The first two was were all misread, and then they couldn't get out of their original ideas.It's been a long time since the other team-mates completely pushed down the rewritten monotonous queue.Then the Cartesian tree of the caption was a fog, so the monotonous queue was rewritten.The following is the post-competition supplement 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

As we all know: \(\int^{\infty}{0} \frac{1}{1+x^2} DX = \frac{\pi}{2}\).Then give you n numbers, ask:
\[\frac{1}{\pi} \int^{\infty}_{0} \frac{1}{\prod^{n}_{i=1}(a_i^2+x^2)} dx\]

Then you'll probably get a fraction and need to formalize (\frac{p}{q}\) into \(p*q^{-1} mod(1e^9+7)\).

A high number of 60 + chickens drift by. It's no wonder I can't push them out.

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

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

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

Long live with questions

#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

There is a string of length \(2(n+m)\) whose subsequences can be split into: "n AB s, m BA".Ask how many sorting methods are there in total.

emmm... maybe there are still fewer dp brushes, think of dp but don't expect to transfer by the number of A and B.

\(dp[i][j] indicates that the prefix has I A, J B\) and then runs \(n^2\) to transfer by inserting A and B each time. The boundary needs to be dealt with more.

#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] indicates that the prefix has 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) {
                    // Since i starts at 0, it can only reach n-1 at most; the same is true for the back
                    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

Given the three points of a triangle, there is now a point P that falls randomly within the triangle. Ask the expected value \ (E = max\{S_{PAB},S_{PBC},S_{PCA}\}\), and multiply the output by 36.

This multiply by 36 gives you the essence.. Because the data is too large, you can't use Helen's formula directly (I'm WA anyway), so long and cut-and-fill are used to eliminate the error.Then by calculating (random number statistics and guessing again), we find that the answer should be \(frac{11}{2}\).Don't ask why, ask what your 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, you can decide which is bigger.

Apparently direct division... is not accurate enough, right, and then think about using \\int128\.Then none of the people in the team will read in, and then long long is read in first, and it's enough to make a strong calculation.

#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;
}

Trust me, I'll make up for it.

Topics: PHP