1. 程式人生 > >BestCoder Round #41 A B C

BestCoder Round #41 A B C

A:52張牌,列舉每種可以的情況,統計已經有x張牌了,需要換的就是5 - x張,不斷維護最小值就可以了

B:敗的情況只有2種,兩個串奇偶性不同,兩個串完全相同,所以簡單統計一下就可以了,最後除上總情況C(n, 2)即可

C:這題看了官方題解才會的,dp[i][j] = dp[i - j][j] + dp[i - j][j - 1],自己也是沒想到,弱爆了,具體的可以看官方題解,有的遞推式子,然後滾動陣列一發就可以了

程式碼:

A:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int t;
char s[15];
int vis[105];

int gao1(int x) {
    int cnt = 5;
    for (int i = 0; i <= 4; i++) {
        if (vis[x + i]) cnt--;
    }
    return cnt;
}

int gao2(int x) {
    int cnt = 5;
    for (int i = 9; i < 13; i++) {
        if (vis[x + i]) cnt--;
    }
    if (vis[x]) cnt--;
    return cnt;
}

int cal() {
    int ans = 10;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j <= 8; j++)
            ans = min(ans, gao1(i * 13 + j));
        ans = min(ans, gao2(i * 13));
    }
    return ans;
}

int main() {
    scanf("%d", &t);
    while (t--) {
        memset(vis, 0, sizeof(vis));
        for (int i = 0; i < 5; i++) {
            scanf("%s", s);
            int tmp = (s[0] - 'A') * 13;
            int sum = 0;
            for (int i = 1; s[i]; i++)
                sum = sum * 10 + s[i] - '0';
            tmp += sum - 1;
            vis[tmp] = 1;
        }
        printf("%d\n", cal());
    }
    return 0;
}

B:
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;

const int N = 20005;

int t, n;
string str[N];
int len[N * 10];
int odd, even;

int gcd(int a, int b) {
    if (!b) return a;
    return gcd(b, a % b);
}

int main() {
    cin >> t;
    while (t--) {
        cin >> n;
        odd = even = 0;
        int Max = 0;
        memset(len, 0, sizeof(len));
        for (int i = 0; i < n; i++) {
            cin >> str[i];
            int tmp = str[i].length();
            Max = max(Max, tmp);
            if (tmp % 2) odd++;
            else even++;
            len[tmp]++;
        }
        if (n < 2)
            printf("0/1\n");
        else {
            int zi = 0;
            int mu = n * (n - 1) / 2;
            sort(str, str + n);
            for (int i = 1; i <= Max; i++) {
                if (i % 2) {
                    zi += len[i] * even;
                }
            }
            int cnt = 1;
            for (int i = 1; i < n; i++) {
                if (str[i] == str[i - 1]) {
                    cnt++;
                } else {
                    zi += cnt * (cnt - 1) / 2;
                    cnt = 1;
                }
            }
            zi += cnt * (cnt - 1) / 2;
            int d = gcd(zi, mu);
            printf("%d/%d\n", zi / d, mu / d);
        }
    }
    return 0;
}

C:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;

const int MOD = 998244353;

int t, n, c, l, r;

int dp[505][505];

int main() {
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d%d%d", &n, &c, &l, &r);
        l -= c; r -= c;
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        int ans = 0;
        for (int i = 1; i <= r; i++) {
            memset(dp[i % 500], 0, sizeof(dp[i % 500]));
            for (int j = 1; j * (j + 1) / 2 <= i; j++) {
                dp[i % 500][j] = (dp[(i - j) % 500][j] + dp[(i - j) % 500][j - 1]) % MOD;
                if (i >= l) ans = (ans + dp[i % 500][j]) % MOD;
            }
        }
        if (l == 0) ans++;
        if (r == n) ans--;
        ans = (ans + MOD) % MOD;
        printf("%d\n", ans);
    }
    return 0;
}


相關推薦

BestCoder Round #41 A B C

A:52張牌,列舉每種可以的情況,統計已經有x張牌了,需要換的就是5 - x張,不斷維護最小值就可以了 B:敗的情況只有2種,兩個串奇偶性不同,兩個串完全相同,所以簡單統計一下就可以了,最後除上總情況C(n, 2)即可 C:這題看了官方題解才會的,dp[i][j] = dp

BestCoder Round #40 A B C

A,水題,直接列舉到sqrt B,每次對於每一位列舉,如果小於當前位,那麼答案可以計算出來,增加得答案為:設3個部分,前完全一樣的部分a,中間新選的一個b,後面的全排列c,這樣就把每部分和每兩部分能夠組成的逆序對個數計算出來,由於n只有100,裡面在去列舉也是沒問題的,主要

Educational Codeforces Round 37 A B C F (暫時)

n) body else if 並查集 fine namespace push swap har A. water the garden Code #include <bits/stdc++.h> #define maxn 210 using namespace

【codeforces Div2】Technocup 2019 - Elimination Round 1(A,B,C)

Technocup 2019 - Elimination Round 1 比賽遲到了15分鐘。 (A) 大水題就不說了,有1輸出HARD,否則輸出NO; #include<bits/stdc++.h> using namespace std; const int max

Codeforces Beta Round #1 A,B,C

In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — numbe

Codeforces Round #426 (Div. 2)A B C題+賽後小結

ase com || namespace inf exp test 鏈接 %d   最近比賽有點多,可是好像每場比賽都是被虐,單純磨礪心態的作用。最近講的內容也有點多,即便是點到為止很淺顯的版塊,刷了專題之後的狀態還是~"咦,能做,可是並沒有把握能A啊"。每場網絡賽,我似乎

AIM Tech Round 4 (Div. 2) A B C

can out cnblogs 並查集 logs using scan 色相 所有 A. Diversity 題意:給出一個字符串,和n,問最多改變多少個字符,使其不同字符最少為n 1 #include<bits/stdc++.h> 2 using nam

Codeforces Round #475 Div. 2 A B C D

rac sca 節點 spa AR 並且 split -s using A - Splits 題意 將一個正整數拆分成若幹個正整數的和,從大到小排下來,與第一個數字相同的數字的個數為這個拆分的權重。 問\(n\)的所有拆分的不同權重可能個數。 思路 全拆成1,然後每次將2個

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)(A,B,C,D)

A. 水題,不多說。 /**/ #include <cstdio> #include <cstring> #include <cmath> #include <cctype> #include <iostream> #include

Educational Codeforces Round 54 (Rated for Div. 2) A B C D E題解

這些題目挺有意思,起碼我都錯過,可能這兩天精力有點不足,腦子不太夠用???   A題連結:http://codeforces.com/contest/1076/problem/A 題意:給定一個字串,最多可以刪掉一個字元,使得字典序最小; 思路:首先跟原串比較的話,某一

CF-Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) A,B,C

A. The King's Race 題目連結:http://codeforces.com/contest/1075/problem/A 題目大意:一個棋盤,(1,1)(n,n)分別一個點,然後給出一個目標點的座標,問誰先到(一次可以走八個方向) 水題,直接輸出: int main(

【Codeforces - Mail.Ru Cup 2018 Round 3 】A.B.C.D.E

前言 又是一個深夜場,本來想給biubiubiu_上個紫,沒想到全程不在狀態,最後四題,E甚至都沒讀題,賽後讀題+寫題直接半小時就過了,開場又是寫錯一個for迴圈的變數,導致7分鐘才過掉a,之後看b感覺是一個好難的題,沒什麼思路,畫個圖想了一個做法,tle,開啟程式碼一看一個O(1e9)

【Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)】 A.B.C.D

前言 在晚上的div2之前開啟的這場,但是自己頭腦貌似不太清醒,全程在寫bug,而且B題不知道自己在寫啥,寫了一百多行?,C也寫了好多bug導致最後的D一眼思路但是沒寫完。希望晚上狀態不要這麼差!QWQ A. Golden Plate 題意 給你一個h*w的長方形邊框,

Codeforces Round #521 (Div. 3) A B C D E

A. Frog Jumping 題目連結:https://codeforces.com/contest/1077/problem/A 題目大意:t組測試資料,從0開始,向前跳a,向後跳b,跳k次,輸出最後所在的位置。 題解:大水題,直接輸出就行了 int main() { std:

Codeforces Round #520 (Div. 2) A B C D

A. A Prank 題目連結:http://codeforces.com/contest/1062/problem/A 題目大意:n個數,輸入n個數,然後對於這些數,看最多能夠擦除多少個數,還能還原出原陣列。 這些數範圍:1~1000。 方法:下標相減==裡面的元素值相減則是能夠刪

【codeforces】Round #522 (Div. 2) A+B+C+D

目錄 【A. Kitchen Utensils】 【B. Personalized Cup】 【C. Playing Piano】 【D. Barcelonian Distance】  【A. Kitchen Utensils】 題目連結:htt

【codeforces】Round #520 (Div. 2) A+B+C+D

目錄 A - A Prank B - Math C - Banh-mi D - Fun with Integers 【A - A Prank】 題目連結:http://codeforces.com/contest/1062/problem/A 【題意】 給你一串序

【Codeforces Round #509 (Div. 2)】A,B,C,D

這是蒟蒻的真·第一場CF...所以其實升了1500+還是不錯吧? 題意:找包含給出的n個數的最短連續序列,輸出新加入的數的最小個數。 分析:排序+掃描即可。 #include<i

【浮*光】Educational Codeforces Round 51 (Rated for Div. 2) A,B,C,D 題解

最少的操作使原串變成有數字+大小寫字母的串。 #include<iostream> #include<cstdio> #include<cstring> #i