AcWing 周赛第 65 场

一、4603.最大价值

1、原题链接:4603. 最大价值 - AcWing题库

2、解题思路:

        遍历给定的字符串每当遇到‘A’ 就统计其后跟着多少个连续的‘P',并且更新最大值。

3、代码:

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int t;
    cin >> t;
    
    while ( t -- ) {
        int n;
        cin >> n;
        
        string str;
        cin >> str;
        
        int res = 0;
        for(int i = 0; i < str.size(); i ++) {
            int tmp = 0;
            if(str[i] == 'A' && str.size() > 1) {
                while(str[ i + 1 ] == 'P' && i < str.size()) {
                    tmp ++;
                    i ++;
                }
            }
            
            if(tmp > res) res = tmp;
        }
        cout << res << endl;
    }
    return 0;
}

 

二、4604. 集合询问

1、原题链接:4604. 集合询问 - AcWing题库

2、解题思路:

        本题可以用数组模拟哈希表来保存每个数,本解法的核心思路就是把每一位对应的奇偶性相同的数存在一起,因此我们就可以简化后期去验证的时间。

3、代码:

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1 << 18;

int cnt[N];

int main()
{
    int t;
    cin >> t;
    
    char op[2], str[20];
    while ( t -- ) {
        
        scanf("%s%s", op, str);
        
        int x = 0;
        for(int i = 0; str[i]; i ++ ) {
            x = x * 2 + str[i] % 2;
        }
        
        if(*op == '+') cnt[x] ++;
        else if(*op == '-') cnt[x] --;
        else printf("%d\n", cnt[x]);
    }
    
    return 0;   
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值