Acdream original group competition (18) semi AK's dream

Source: Internet
Author: User
Tags acos
Acdream original group competition (18) semi AK's dream

Question Link

A: Just simulate the question.

D: greedy + combined mathematics, which sorts the swords and heroes from small to large. Each computation allows the hero to use the first few swords CNT, CNT: How many people can be selected by the hero, and how many people can be multiplied by CNT?

F: DP, DP [I] [J] [2] indicates the day I, and J modifications are used. The current status is A or B, and then you can move the changes.

G: Water question. You can simply use a string to process the question. Add leading zeros to all numbers for easy judgment.

H: ry. Use the sine theorem to confuse the cosine theorem.

I: Water question, which can be output directly at each position, and can be simplified by using GCD.

J: Check the query set and reverse process the query. Merge the query with the left and right parts each time. In this way, the number of corresponding parts changes, and output the result in turn.

Code:

A:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std; int n, cur, d; int main() {    int cas = 0;    while (~scanf("%d%d%d", &n, &cur, &d)) {        printf("Case #%d: ", ++cas);        int l = max(1, cur - d);        if (cur == 1) printf("[<<]");        else printf("(<<)");        if (l != 1) printf("[...]");        for (int i = l; i < cur; i++)            printf("(%d)", i);        printf("[%d]", cur);        int r = min(n, cur + d);        for (int i = cur + 1; i <= r; i++)            printf("(%d)", i);        if (r != n) printf("[...]");        if (cur == n) printf("[>>]");        else printf("(>>)");        printf("\n");    }    return 0;}

D:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std; const int N = 100005;const int MOD = 1000000007;typedef long long ll; int t, n, a[N], b[N]; int main() {    int cas = 0;    scanf("%d", &t);    while (t--) {        scanf("%d", &n);        for (int i = 0; i < n; i++)            scanf("%d", &a[i]);        for (int i = 0; i < n; i++)            scanf("%d", &b[i]);        sort(a, a + n);        sort(b, b + n);        int ans = 1;        int l = 0;        for (int i = 0; i < n; i++) {            while (l < n && b[i] >= a[l]) l++;            ans = (ll)ans * (l - i) % MOD;        }        printf("Case #%d: %d\n", ++cas, ans);    }    return 0;}

F:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std; const int N = 105;const int INF = 0x3f3f3f3f;int n, m, a[N], Max[N][55][2], Min[N][55][2], num[2];char str[N]; int main() {    num[0] = 1;    num[1] = -1;    int cas = 0;    while (~scanf("%d", &n)) {        scanf("%s%d", str + 1, &m);        memset(Max, -INF, sizeof(Max));        memset(Min, INF, sizeof(Min));        for (int i = 1; i <= n; i++)            a[i] = str[i] - 'A';        Max[0][0][0] = 0;        Min[0][0][0] = 0;        for (int i = 0; i < n; i++) {            for (int j = 0; j <= m; j++) {                for (int k = 0; k < 2; k++) {                    if (a[i + 1]) {                        Max[i + 1][j][!k] = max(Max[i + 1][j][!k], Max[i][j][k]);                        Max[i + 1][j + 1][k] = max(Max[i + 1][j + 1][k], Max[i][j][k] + num[k]);                        Min[i + 1][j][!k] = min(Min[i + 1][j][!k], Min[i][j][k]);                        Min[i + 1][j + 1][k] = min(Min[i + 1][j + 1][k], Min[i][j][k] + num[k]);                    } else {                        Max[i + 1][j + 1][!k] = max(Max[i + 1][j + 1][!k], Max[i][j][k]);                        Max[i + 1][j][k] = max(Max[i + 1][j][k], Max[i][j][k] + num[k]);                        Min[i + 1][j + 1][!k] = min(Min[i + 1][j + 1][!k], Min[i][j][k]);                        Min[i + 1][j][k] = min(Min[i + 1][j][k], Min[i][j][k] + num[k]);                    }                }            }        }        int ans1 = INF, ans2 = -INF;        int st = m % 2;        for (int i = st; i <= m; i += 2) {            ans1 = min(ans1, Min[n][i][0]);            ans1 = min(ans1, Min[n][i][1]);            ans2 = max(ans2, Max[n][i][0]);            ans2 = max(ans2, Max[n][i][1]);        }        int ans = -INF;        ans = max(ans2, -ans1);        printf("Case #%d: %d\n", ++cas, ans);    }    return 0;}

G:

#include <cstdio>#include <cstring>#include <string>#include <iostream>using namespace std; string str; int main() {    while (cin >> str) {        string a, b, c;        a = "000000000000000000000000032767";        b = "000000000000000000002147483647";        c = "000000000009223372036854775807";        int s = 0;        int n = str.length();        if (str[0] == '-') {            n--;            s++;            a = "000000000000000000000000032768";            b = "000000000000000000002147483648";            c = "000000000009223372036854775808";        }        string tmp = "";        for (int i = 30 - n; i > 0; i--)            tmp += '0';        for (int i = s; i < n + s; i++)            tmp += str[i];        str = tmp;        if (str <= a) printf("short\n");        else if (str <= b) printf("int\n");        else if (str <= c) printf("long long\n");        else printf("It is too big!\n");    }    return 0;}


H:

#include <cstdio>#include <cstring>#include <cmath> const double eps = 1e-9;const double pi = acos(-1.0); double a, b, c, d; double solve() {    if (fabs(a) < eps)        return 0.0;    if (fabs(c) < eps)        return 0.0;    if (fabs(b) < eps)        return c;    if (fabs(d) < eps)        return b + c;    a = a / 180 * pi; b = b / 180 * pi; c = c / 180 * pi; d = d / 180 * pi;    double AB = 1.0;    double AOB = pi - b - c;    double ADB = pi - a - b - c;    double AEB = pi - b - c - d;    double A = a + b, B = c + d;    double AO = AB * sin(c) / sin(AOB);    double BO = AB * sin(b) / sin(AOB);    double BD = AB * sin(A) / sin(ADB);    double AE = AB * sin(B) / sin(AEB);    double DO = BD - BO;    double EO = AE - AO;    double DE = sqrt(DO * DO + EO * EO - cos(AOB) * 2 * DO * EO);    double cosx = (DE * DE + EO * EO - DO * DO) / 2 / DE / EO;    double ans = acos(cosx) * 180 / pi;    return ans;} int main() {    while (~scanf("%lf%lf%lf%lf", &a, &b, &c, &d)) {        printf("%.2lf\n", solve());    }    return 0;}

I:
#include <cstdio>#include <cstring> int gcd(int a, int b) {    while (b) {        int tmp = a % b;        a = b;        b = tmp;    }    return a;} int n; int main() {    while (~scanf("%d", &n)) {        int a, b;        for (int i = 0; i < n; i++) {            scanf("%d%d", &a, &b);            int mu = b + 1;            int d = gcd(a, mu);            a /= d; mu /= d;            if (mu < 0) {                a = -a;                mu = -mu;            }            if (mu == 1) printf("%d", a);            else {                printf("%d/%d", a, mu);            }            printf(" ");            printf("%d", b + 1);            printf("%c", i == n - 1 ? '\n' : ' ');        }    }    return 0;}

J:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std; const int N = 1000005; int t, n, m, parent[N]; struct Block {    int id, h;} d[N]; int q[N], vis[N], out[N], on; int find(int x) {    return x == parent[x] ? x : parent[x] = find(parent[x]);} void merge(int u, int v) {    int pa = find(u);    int pb = find(v);    if (pa != pb) parent[pb] = pb;} bool cmp(Block a, Block b) {    return a.h > b.h;} int main() {    int cas = 0;    scanf("%d", &t);    while (t--) {        scanf("%d%d", &n, &m);        d[0].h = d[n + 1].h = -1;        vis[0] = vis[n + 1] = 0;        for (int i = 1; i <= n; i++) {            vis[i] = 0;            parent[i] = i;            scanf("%d", &d[i].h);            d[i].id = i;        }        sort(d + 1, d + n + 1, cmp);        for (int i = 0; i < m; i++)            scanf("%d", &q[i]);        int l = 1;        int ans = 0;        on = 0;        printf("Case #%d:", ++cas);        for (int i = m - 1; i >= 0; i--) {            while (l <= n && q[i] < d[l].h) {                if (vis[d[l].id - 1] && vis[d[l].id + 1]) {                    merge(d[l].id, d[l].id - 1);                    merge(d[l].id, d[l].id + 1);                    ans--;                }                else if (vis[d[l].id - 1])                    merge(d[l].id, d[l].id - 1);                else if (vis[d[l].id + 1])                    merge(d[l].id, d[l].id + 1);                else ans++;                vis[d[l].id] = 1;                l++;            }            out[on++] = ans;        }        for (int i = on - 1; i >= 0; i--)            printf(" %d", out[i]);        printf("\n");    }    return 0;}


Acdream original group competition (18) semi AK's dream

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.