AtCoder Regular Contest 108

本文详细解析了AtCoder Regular Contest 108的四道题目,包括A题的因子枚举,B题的字符串操作,C题的图的连通性判断,以及D题的动态规划求解字符串拓展的可能性。
摘要由CSDN通过智能技术生成

AtCoder Regular Contest 108

A - Sum and Product

题意: 给两个正整数 S, P,问是否存在正整数 N 和 M,满足 N+M=S 和 N*M=P。

题解: 枚举P的因此,然后判断因子相加是否为S即可。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
int const MAXN = 2e5 + 10;
int n, m, T;

int main() {
   
    LL s, p;
    cin >> s >> p;
    for (LL i = 1; i <= p / i; ++i) {
     // 枚举到sqrtx(x)
        if (p % i == 0) {
     // 如果能够整除
            if (i + p / i == s) {
   
                cout << "Yes\n";
                return 0;
            }
        }
    }   
    cout << "No\n";
    return 0;
}

B - Abbreviate Fox

题意: 给一个长度 N 和对应长度的字符串 S,snuke 可以执行以下操作任意次:删除子字符串 fox。问最后字符串 s 的长度是多少。

题解: 使用栈来维护即可,一旦发现fox,删除栈顶的fox

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
int const MAXN = 2e5 + 10;
int n, m, T;
char s[MAXN];

int main() {
   
    cin >> n;
    getchar();
    int top = 0;
    for (int i = 1; i <= n; ++i) {
   
        char c;
        scanf("%c", &c);

        s[top++] = c;
        if (i < 3 || top < 3)
            continue;
        if (s[top - 1] == 'x' && s[top - 2] == 'o' && s[top - 3] == 'f')
            top -
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值