Codeforces Round #657 A、B

题目链接

A、Acacius and String

题意: 给你一个长度为n的字符串s,由小写英文字母和问号组成。是否可以用小写英文字母替换问号,使字符串“abacaba”在结果字符串中作为子字符串出现且仅出现一次。
思路:这题就真的暴力……暴力查找符合该串的即可……
参考了大佬的博客

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f
const int N = 2e5 + 10;
const int maxn=4000;
const double PI= acos(-1.0);
string s = "abacaba";
int findd(string str)
{
    int i, j;
    int cnt = 0;
    for (i = 0; i <= str.size()-7; i++)
    {
        int flag = 1;
        for (j = 0; j < 7; j++)
        {
            if (s[j] != str[i + j])
            {
                flag = 0;
                break;
            }
        }
        if (flag)
            cnt++;
    }
    return cnt;
}
int main()
{
    int t,n;
    string str;
    cin >> t;
    while (t--)
    {
        cin >> n >> str;
        int cnt = findd(str);
        int i, j;
        if (cnt > 1)
        {
            cout << "No" << endl;
            continue;
        }
        if (cnt == 1)
        {
            cout << "Yes" << endl;
            for (i = 0; i < str.size(); i++)
            {
                if (str[i] != '?')cout << str[i];
                else cout << 'z';
            }
            cout << endl;
            continue;
        }
        string tmp = str;
        int flag1 = 1;
        for (i = 0; i <= str.size()-7; i++)
        {
            int flag = 1;
            str = tmp;
            for (j = 0; j < 7; j++)
            {
                if (str[i+j] == '?') str[i + j] = s[j];
                if (str[i+j] != s[j])flag = 0;
            }
            if (flag)
            {
                cnt = findd(str);
                if (cnt == 1)
                {
                    flag1 = 0;
                    cout << "Yes" << endl;
                    for (i = 0; i < str.size(); i++)
                    {
                        if (str[i] != '?')cout << str[i];
                        else cout << 'z';
                    }
                    cout << endl;
                }
                if (flag1 == 0)break;
            }
        }
        if (flag1)
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

B、Dubious Cyrpto

题意:有三个整数a,b,c。满足l<=a,b,c<=r 还有一个整数m=n*a+b-c。n是严格大于0的正整数。给定l,r,m。要求出a,b,c的值。
思路:枚举a即可。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f
const int N = 2e5 + 10;
const double PI= acos(-1.0);
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        ll m,l,r,a,b,c;
        cin >> l >> r >> m;
        ll mx=r-l,mi=l-r;
        for(a=l; a<=r; ++a)
        {
            ll x=m%a;
            ll y=a-x;
            if(y<=mx)
            {
                b=l;
                c=l+y;
                break;
            }
            else if(-x>=mi)
            {
                b=r;
                c=r-x;
                break;
            }
        }
        cout << a << " " << b << " " << c <<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浅梦曾倾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值