xtu1406 stringgame

Source Code

Problem: 1406		User: 20220556****
Memory: 1200K		Time: 249MS
Language: GCC		Result: Accepted
Source Code

#include <stdio.h>
#include <string.h>
int score(int countmax, int len, int playtime)
{
    if (countmax + playtime <= len)
    {
        return countmax + playtime;
    }
    else if (countmax == len)
    {
        if (playtime == 1)
        {
            return len - 1;
        }
        else
        {
            return len;
        }
    }
    else if (countmax + playtime > len)
    {
        return len;
    }
}
int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int n, p;
        scanf("%d %d", &n, &p);
        char Alice[105], Bob[105];
        scanf("%s", Alice);
        scanf("%s", Bob);
        int countAlice[26] = {0}, countBob[26] = {0};
        int alice = 0, bob = 0, countalicemax = 0, countbobmax = 0;
        for (int i = 0; i < n; i++)
        {
            countAlice[Alice[i] - 'a']++;
            countBob[Bob[i] - 'a']++;
        }
        for (int i = 0; i < 26; i++)
        {
            if (countAlice[i] > countalicemax)
                countalicemax = countAlice[i];
            if (countBob[i] > countbobmax)
                countbobmax = countBob[i];
        }

        alice = score(countalicemax, n, p);
        bob = score(countbobmax, n, p);

        if (alice > bob)
        {
            printf("Alice\n");
            continue;
        }
        else if (alice == bob)
        {
            printf("Draw\n");
            continue;
        }
        else if (alice < bob)
        {
            printf("Bob\n");
            continue;
        }
    }
}

找到计分规则就好了

首先要找到最多的字母的数量,你要赢肯定要变最多的

当回合数不够时打尽力局,最高分为最大的字母加回合数

当回合数大于补满所要的步数时,若刚刚好大一个,只能的max-1分,因为比如wwwwwwww你要改变一个就会少一分

当回合数不止大一个时直接拉满

比如wwwwwwww还有大于一次的机会你就w->x->w或者w->q->p->....->w

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值