Codeforces Round #345 (Div. 2)

Source: Internet
Author: User

DFS A-joysticks

Too troublesome direct Dfs burst search bar, there is a pit point is the current power <=1 can no longer power down, the direct end.

#include <bits/stdc++.h>typedef long long ll;const int N = 1e5 + 5;int ans = 0;void DFS (int A, int b, int step) {
   if (a <= 0 | | b <= 0) {        ans = std::max (ans, step); return;    }    if (A < b && b-2 >= 0) {        DFS (A + 1, b-2, step + 1);    } else if (a >= b && a-2 >= 0) {        DFS (a-2, B + 1, step + 1);}    } int main () {    int A, b;   Std::cin >> a >> b;    Ans = 0;    DFS (A, b, 0);    Std::cout << ans << ' \ n ';    return 0;}

Construction + greedy b-beautiful paintings

Every time you remove an increment sequence that is not repeated until the collection is empty

#include <bits/stdc++.h>typedef long long ll;const int n = 1e5 + 5;std::vector<int> vec;int main () {    int n ;  Std::cin >> N;    for (int x, i=0; i<n; ++i) {        std::cin >> x; vec.push_back (x);    }    Std::sort (Vec.begin (), Vec.end ());    int ans = 0;    while (Vec.size () > 0) {        std::vector<int> tmp;        int pre = 0, num = 0;        for (auto X:vec) {            if (x > Pre) {                num++; pre = x;            } else {                tmp.push_back (x);            }        }        Ans + = num-1; VEC = tmp;    }    Std::cout << ans << ' \ n ';    return 0;}

Math + tolerance C-watchmen

Simplification formula gets found pair (i, j) Xi = = XJ | | Yi = = yj. Find two times and let it go. Map to do better.

#include <bits/stdc++.h>typedef long long ll;const int N = 2e5 + 5;const int INF = 1e9 + 7;std::p air<int, int> Point[n];ll Calc (int N) {return 1LL * N * (n-1)/2;} BOOL CMPX (std::p air<int, int> A, std::p air<int, int> b) {return A.first < B.first;} BOOL Cmpy (std::p air<int, int> A, std::p air<int, int> b) {return A.second < B.second;}    int main () {int n; scanf ("%d", &n);        for (int x, y, i=0; i<n; ++i) {scanf ("%d%d", &x, &y);    Point[i] = Std::make_pair (x, y);    } std::sort (Point, Point+n, cmpx);    ll ans = 0;    int x = inf, y = inf, num = 1;        for (int i=0; i<n; ++i) {if (x = = Point[i].first) {num++;            } else {x = Point[i].first;            if (num > 1) {ans + = calc (num);        num = 1;    }} if (num > 1) {ans + = calc (num);    } std::sort (Point, Point+n, cmpy); x = INF; y = INF; num = 1;        for (int i=0; i<n; ++i) {if (y = = Point[i].second) {num++;            } else {y = Point[i].second;            if (num > 1) {ans + = calc (num);        num = 1;    }} if (num > 1) {ans + = calc (num);    } std::sort (point, Point+n); x = INF; y = INF;    num = 1;        for (int i=0; i<n; ++i) {if (x = = Point[i].first && y = = Point[i].second) {num++;            } else {x = Point[i].first, y = point[i].second;            if (num > 1) {ans-= calc (num);        num = 1;    }} if (num > 1) {ans-= calc (num);    } printf ("%i64d\n", ans); return 0;}

Points D-image Preview

Test instructions: Browse pictures, browse, swipe, and invert takes time to ask how many images to browse in T time.

Analysis: Define two pointers from,to, the feasible scheme is n+1->from,from->n+1,n+1->to or N+1->to,to->n+1,n+1->from, and from->to. The first two repeat sliding can choose a small distance, the third as long as the definition of to=n+1 is right. In fact, you can do it with two points.

#include <bits/stdc++.h>typedef long long ll;const int n = 5e5 + 5;char str[2*n];ll tim[2*n];int N, a, B, T;ll get_t IME (int from, int. to) {    LL ret = Tim[from]-tim[to-1];    int move = from-to + std::min (from-(n+1), (n+1)-to);    return ret + 1ll * A * move;} int main () {    scanf ("%d%d%d%d", &n, &a, &b, &t);    scanf ("%s", str + 1);    for (int i=1; i<=n; ++i) {        Tim[i] = (str[i] = = ' W '? (b+1): 1);    }    for (int i=n+1; i<=2*n; ++i) {        tim[i] = tim[i-n];    }    for (int i=1; i<=2*n; ++i) {        Tim[i] + = tim[i-1];    }    int ans = 0;    int from = n + 1;    for (int to=2; to<=n+1; ++to) {while        (from < to+n-1 && Get_time (from+1, to) <= T) from++;        if (Get_time (from, to) <= T) ans = std::max (ans, from-to + 1);    }    printf ("%d\n", ans);    return 0;}

E-table Compression

Test instructions: To a matrix, the new matrix, so that the original matrix peers, the same column size relationship is not changed, and make the maximum value of the novel matrix is minimal. i.e. discretization

Analysis:

Codeforces Round #345 (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.