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;
}
时间: 2024-12-29 11:26:55

BestCoder Round #41 A B C的相关文章

HDU 5228 ZCC loves straight flush( BestCoder Round #41)

题目链接:pid=5228">ZCC loves straight flush pid=5228">题面: pid=5228"> ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 827    Accepted Submission(s): 340

BestCoder Round #41 -- (A,B)

题目传送:BestCoder Round #41 A.ZCC loves straight flush 思路:简单题,不过刚开始没看清题,wa了好几次,然后才发现输入不连续也可以,就是说每个同一花色的牌都可以放在一块,不用在意输入顺序,感觉这里题目应该说清楚点好些 AC代码(略挫,比赛时写的都比较乱): #include <cstdio> #include <cstring> #include <iostream> #include <algorithm>

暴力 BestCoder Round #41 1001 ZCC loves straight flush

题目传送门 1 /* 2 m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 3 ╰· 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 using namespace std; 11 12 const int MAXN = 1

BestCoder Round #41

闲来无事打打BC,想必也是极好的,先来个flag:我要刷完所有的BC!! 题A hdu 5228 题意:给你五张牌,问你能够换最少的牌数实现同花顺. 题解:暴力乱搞,才五张牌,枚举所有组成同花顺的可能,然后匹配看还要补多少张即可. 1 /*zhen hao*/ 2 #include <bits/stdc++.h> 3 using namespace std; 4 5 #define lson l, m, rt*2 6 #define rson m + 1, r, rt*2+1 7 #defin

BestCoder Round #41 1002

Problem Description ZCC has got N strings. He is now playing a game with Miss G.. ZCC will pick up two strings among those N strings randomly(A string can't be chosen twice). Each string has the same probability to be chosen. Then ZCC and Miss G. pla

hdu 5230 ZCC loves hacking(BestCoder Round #41)

ZCC loves hacking                                                   Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others) Total Submission(s): 126    Accepted Submission(s): 49 Problem Description Now, a Codefires roun

BestCoder Round #41 1001——ZCC loves straight flush

Problem Description After losing all his chips when playing Texas Hold'em with Fsygd on the way to ZJOI2015, ZCC has just learned a black technology. Now ZCC is able to change all cards as he wants during the game. ZCC wants to get a Straight Flush b

BestCoder Round #41 记。

大概整个过程都是很绝望的吧. 发现自己在七点之前是肯定搞不定网了..有冲动跑到机房去打 但是又不喜欢那样的气氛 这可是shi的场呢...好难过啊... 后来..好像是在和lyd讨论怎么把网络复原的过程中突然好了..   做A题的过程完全不想回忆了...网站慢得我都不敢去修改默认的语言怕又挂掉.. 然后好久没写pas了爆出了几十处编译错误.. B写的过程稍微顺利一点..但是题目理解了很久啊..大概是弃疗了三遍以后第四次看题目才看懂的 交的第一发是WA的于是开始思考解题思路是否有问题 然后发现没有判

hdu 5229 ZCC loves strings(Bestcoder Round #41)

ZCC loves strings                                                       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others) Total Submission(s): 286    Accepted Submission(s): 108 Problem Description ZCC has got N st