Codeforces Round #348 (VK Cup 2016-round 2)

Source: Internet
Author: User

A-little Artem and presents (DIV2)

1 2 1 2 This will do it.

#include <bits/stdc++.h>typedef long long ll;const int n = 1e5 + 5;int main () {    int N; scanf ("%d", &n); 
   
    int ans = n/3 * 2;    if (n% 3) {        ans++;    }    printf ("%d\n", ans);    return 0; 
    }
   

b-little Artem and Grasshopper (DIV2)

Water problem, violent simulation

#include <bits/stdc++.h>typedef long long ll;const int n = 1e5 + 5;char str[n];int a[n];int main () {    int n; scan F ("%d", &n);    scanf ("%s", str);    for (int i=0; i<n; ++i) {        scanf ("%d", a+i);    }    int now = 0;    while (true) {        if (now < 0 | |->= N) {break            ;        }        if (a[now] = =-1) {            puts ("INFINITE");            return 0;        }        if (str[now] = = ' > ') {            int pre = now            ; now = Now + A[now];            A[pre] =-1;        } else {            int pre = now;            now = Now-a[now];            A[pre] =-1;        }    }    Puts ("finite");    return 0;}

Construction c-little Artem and Matrix (DIV2)

Do it backwards, and the loop comes back.

#include <bits/stdc++.h>typedef long long ll;const int N = 1e2 + 5;const int Q = 1e4 + 5;int a[n][n];int t[q], row[q    ], Col[q], X[q];int main () {int n, m, Q; scanf ("%d%d%d", &n, &m, &q);        for (int i=1; i<=q; ++i) {scanf ("%d", t+i);        if (t[i] = = 1) {scanf ("%d", row+i);        } if (t[i] = = 2) {scanf ("%d", col+i);        } if (t[i] = = 3) {scanf ("%d%d%d", Row+i, Col+i, x+i);    }//printf ("%d%d%d%d\n", T[i], row[i], col[i], x[i]);            } for (int i=q; i>=1;-I.) {if (t[i] = = 1) {int last = a[row[i]][m];            for (int j=m; j>=2;--j) {a[row[i]][j] = a[row[i]][j-1];        } a[row[i]][1] = last;            } if (t[i] = = 2) {int last = a[n][col[i]];            for (int j=n; j>=2;--j) {A[j][col[i]] = a[j-1][col[i]];        } A[1][col[i]] = last; } if (t[i] = = 3) {A[row[i]][col[i]] = x[i]; }} for (int i=1; i<=n; ++i) {for (int j=1; j<=m; ++j) {printf ("%d%c", a[i][j], j = = m?        ' \ n ': '); }} return 0;}

Mathematics d-little Artem and Dance (DIV2)

Test instructions: Boys and girls around the circle to dance, the position of the girl is not changed, the boys can move x girls or the adjacent boys parity swap, ask the last boy's arrangement

Analysis: The key point of the problem is that the odd Boy's circle order is constant, the even number is unchanged, but the location of the starting point changes, so as long as the two start operation on the line.

#include <bits/stdc++.h>typedef long long ll;const int N = 1e6 + 5;int ans[n];int main () {    int p0 = 0, p1 = 1;
   int N, Q; scanf ("%d%d", &n, &q);    for (int i=0; i<q; ++i) {        int type; scanf ("%d", &type);        if (type = = 1) {            int x; scanf ("%d", &x);            P0 = (p0 + x + N)% n;            P1 = (p1 + x + N)% n;        } else {            P0 = p0 ^ 1;            P1 = p1 ^ 1;        }    }    for (int i=0; i<n; i+=2) {        ans[(p0+i)%n] = i + 1;    }    for (int i=1; i<n; i+=2) {        ans[(p1+i-1)%n] = i + 1;    }    for (int i=0; i<n; ++i) {        printf ("%d%c", ans[i], i = = n-1? ' \ n ': ');    }    return 0;}

Math + front (back) suffix c-little Artem and Random Variable (DIV1)

Test instructions: Probability of a known p (max (b) =k) and P (min (b) =k), p (a=k) and P (b=k)

Analysis:

P (A = k) = P (a <= k)-P (a <= k-1) p (Max (A, b) <= k) = P (a <= k) * p (b <= k)

P (min (A, b) >= k) = P (a >= k) * p (b >= k) = (1-p (a <= k-1)) * (1-p (b <= k-1))

That

 

Solving the equations and thereby obtaining and

#include <bits/stdc++.h>const int n = 1e5 + 5;double p[n], q[n], A[n], B[n];int main () {    int n; scanf ("%d", &am P;N);    for (int i=1; i<=n; ++i) {        scanf ("%lf", p+i);        P[i] + = p[i-1];    }    for (int i=1; i<=n; ++i) {        scanf ("%lf", q+i);    }    for (int i=n; i>=1;-I.) {        Q[i] + = q[i+1];    }    for (int i=1; i<=n; ++i) {        double A = p[i], B = q[i+1];        Double C = b-a-1;        Double delta = sqrt (Std::max (c*c-4 * A, 0.0));        A[i] = (-c+delta)/2;        B[i] = (-c-delta)/2;    }    for (int i=1; i<=n; ++i) {        printf ("%.10f%c", A[i]-a[i-1], i = = n? ' \ n ': ');    }    for (int i=1; i<=n; ++i) {        printf ("%.10f%c", B[i]-b[i-1], i = = n? ' \ n ': ');    }    return 0;}

  

Codeforces Round #348 (VK Cup 2016-round 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.