ACdream原創群賽(18)のAK's dream,acdream

來源:互聯網
上載者:User

ACdream原創群賽(18)のAK's dream,acdream
ACdream原創群賽(18)のAK's dream

題目連結

A:水題,直接類比題意去搞即可

D:貪心+組合數學,把劍和英雄都從小到大排序,每次計算該英雄能用前幾把劍cnt,cnt減去之前有多少人就是該英雄能選的,種數乘上cnt - 之前有多少人

F:DP,dp[i][j][2]表示第i天,用了j次修改,目前狀態是A還是B,然後去轉移即可

G:水題,直接用字串處理即可,把數字都加上前置字元為零方便判斷

H:幾何,利用正弦定理,餘弦定理亂搞就可以了

I:水題,直接每個位置推出來輸出,化簡利用gcd即可

J:並查集,把詢問逆向處理,每次多一塊,就和左邊和右邊合并,這樣對應的塊數跟著變化,最後再反過來輸出即可

代碼:

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





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.