Codeforces Round #353 (Div. 2)

Source: Internet
Author: User

Mathematics a-infinite Sequence

Arithmetic progression, when the tolerance is 0, it's a special award.

#include <bits/stdc++.h>typedef long long ll;const int N = 1e5 + 5;int main () {    int A, b, C;    scanf ("%d%d%d", &a, &b, &c);    BOOL flag = TRUE;    if (c = = 0) {        if (a = = b) {            flag = true;        } else {            flag = false;}    } else {        int d = (b- a)/C;        if (d >= 0 && (b-a)% c = = 0) {            flag = true;        } else {            flag = false;        }    }    if (flag) {        puts ("YES");    } else {        puts ("NO");    }    return 0;}

Mathematics b-restoring Painting

Test instructions: 3*3 matrix, already filled a,b,c,d four numbers, asked to fill out the number of four 2*2 sub-matrices and the equal number of schemes, all numbers range in [1, N].

Analysis: Quite interesting topic, it is obvious that the center of the number is public,? From top to bottom from left to right set to x1,x2,x3,x4x5, then meet x1+a+b=x4+b+d-x4 = x1 + (a-d), x2=x1+ (b-c), x5=x1+ (a+b-c-d), because X2, X4, X5 range in [1, n], can get a The minimum feasible interval of a x1, and then *x3 the feasible interval (n). Of course the O (N) enumeration is also possible.

#include <bits/stdc++.h>typedef long long ll;const int n = 1e5 + 5;int main () {    int N, A, B, C, D;    scanf ("%d%d%d%d%d", &n, &a, &b, &c, &d);    int D1 = a-d, d2 = b-c, D3 = a + b-c-D;    int L = 1, r = N;    L = Std::max (L, 1-d1);    R = Std::min (r, N-D1);    L = Std::max (L, 1-d2);    R = Std::min (r, N-D2);    L = Std::max (L, 1-d3);    R = Std::min (r, n-d3);    if (l <= r) {        long long ans = 1ll * (r-l + 1) * N;        Std::cout << ans << ' \ n ';    } else {        puts ("0");    }    return 0;}

Mathematics C-money Transfers

Test instructions: N numbers have positive negative, sum 0, adjacent numbers can be assigned, ask the minimum operand to make all the numbers become 0.

Analysis: If a length of L number sum is 0, up to L-1 times can make each number 0. Dividing n numbers into m segments is 0, so the answer is n-m, so Cnt[k] is the largest and represents M Max (the last group is-k+k).

#include <bits/stdc++.h>int main () {Std::ios::sync_with_stdio (false); Std::cin.tie (0); Std::map<long Long, int> mp;int n;std::cin >> n;long long sum = 0;int mx = 0;for (int i=0; i<n; ++i) {int x;std::cin >> X;SU M + = X;MP[SUM]++;MX = Std::max (mx, mp[sum]);} Std::cout << n-mx << ' \ n '; return 0;}

Set d-tree Construction

Test instructions: Build a tree two fork tree according to BST and ask the parent node of the currently inserted point.

Analysis: Set simulates the balance tree, lower_bound find the location.

#include <bits/stdc++.h>const int N = 1e5 + 5;std::set<int> st;std::map<int, int> left, Right;int main () {    int n, x;    scanf ("%d", &n);    scanf ("%d", &x);    St.insert (x);    int ans;    for (int i=0; i<n-1; ++i) {        scanf ("%d", &x);        Auto it = st.lower_bound (x);        if (it = St.end () && left.count (*it) = = 0) {            left[*it] = x;            ans = *it;        } else {            --it;            Right[*it] = x;            ans = *it;        }        St.insert (x);        printf ("%d", ans);    return 0;}

DP e-trains and statistic

Test instructions: The first station can go to [i+1, A[i]] position, p (i, j), from I to J at least a few times to ride. Please

Analysis: Defines Dp[i] represents the minimum number of rides, from [I+1, N] a[m] The largest dp[m] transfer, ...

#include <bits/stdc++.h>const int N = 1e5 + 5;int a[n];long long dp[n];std::p air<int, int> mx[n][20];int n;voi D Init_st () {    for (int i=0; i<n; ++i) {        mx[i][0] = {A[i], i};    }    for (int j=1; (1<<J) <=n; ++J) {        for (int i=0; i+ (1<<j) -1<n; ++i) {            Mx[i][j] = Std::max (Mx[i][j-1], mx[i+ (1<< (j-1))][j-1]) ;        }    }} int Query_max (int l, int r) {    int k = 0; while (1<< (k+1) <= r-l + 1) k++;    Return Std::max (Mx[l][k], mx[r-(1<<k) +1][k]). Second;} int main () {    scanf ("%d", &n);    A[n-1] = n-1;    for (int i=0; i<n-1; ++i) {        scanf ("%d", a+i);        a[i]--;    }    Init_st ();    A long long ans = 0;    Dp[n-1] = 0;    for (int i=n-2; i>=0;-I.) {        int p = Query_max (i + 1, a[i]);        Dp[i] = dp[p]-(a[i]-p) + n-i-1;        Ans + = Dp[i];    }    printf ("%i64d\n", ans);    return 0;}

  

Codeforces Round #353 (Div. 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.