Codeforces Round #834 (Div. 3) A~E泛做

A.Yes-Yes?

构造一个N=50的字符串,判断是不是子串即可。

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define cerr(x) std::cerr << (#x) << " is " << (x) << '\n'
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
#define PII pair<int, int>
#define pdd pair<double,double>
#define PLL pair<LL,LL>

#define LL long long

const double CLOCKS_PER_SECOND = ((clock_t) 1000);
const double CLOCKS_PER_MILLISECOND = ((clock_t) 1);
const int N = 2e5 + 10, M = 1e8, mod = 1e9 + 7, inf = 0x3f3f3f3f;
const double eps = 1e-6;
//#define x first
//#define y second

int T;
const char ch[] = "Yes";
char t[500 + 10], tot;

void solve() {
    int n, ans = 0;
    char s[50 + 10];
    cin >> s;

    if (strstr(t, s)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

signed main() {
    IOS;
    cin >> T;
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 3; j++)
            t[tot++] = ch[j];
    }
    //cout << t << endl;
    while (T--) {
        solve();
    }
}

B.Lost Permutation

设最高项数为t,因为排列是个等差数列,所以构造式子:

t2+t2(sum+s)=0

其中sum是给定数列元素之和。

t+12(sum+s)t=0可知t的范围是[m,2(sum+s)m+1],枚举。

上述推导都基于等差数列的充分性,对于枚举满足的t仍需要判断是否仅满足和相等而不是一个合法排列。这里我手动构造了排列,看是否满足条件。

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define cerr(x) std::cerr << (#x) << " is " << (x) << '\n'
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
#define PII pair<int, int>
#define pdd pair<double,double>
#define PLL pair<LL,LL>

#define LL long long

const double CLOCKS_PER_SECOND = ((clock_t) 1000);
const double CLOCKS_PER_MILLISECOND = ((clock_t) 1);
const int N = 2e5 + 10, M = 1e8, mod = 1e9 + 7, inf = 0x3f3f3f3f;
const double eps = 1e-6;
//#define x first
//#define y second

int T;

void solve() {
    LL m, s, a[50 + 5];
    cin >> m >> s;
    map<LL, LL> m2;
    LL sum = 0;
    for (int i = 1; i <= m; i++) {
        cin >> a[i];
        m2[a[i]]++;
        sum += a[i];
    }
    for (int i = 1; i <= 50; i++)
        if (m2[i] >= 2) {
            cout << "NO" << endl;
        }
    for (LL t = m; t <= 2 * (sum + s) / (m + 1); t++) {
        if (t * t + t - 2 * (sum + s) == 0) {
            LL res = 0;
            for (LL i = 1; i <= t; i++) {
                if (m2[i]) continue;
                res += i;
            }
            if (res + sum == t * (t + 1) / 2) {
                cout << "YES" << endl;
                return;
            }
        }
    }
    cout << "NO" << endl;
}

signed main() {
    IOS;
    cin >> T;
    while (T--) {
        solve();
    }
}

C.Thermostat

分析样例的结论是,答案只能在1,0,1,2,3中出现。

  • 如果abs(ba)>=x,一步就能跳过去,ans=1

  • 如果a=bans=0

接下来进行分析,a只能沿着以下路径到达b,即a->l->b、a->r->b、a->l->r->b、a->r->l->b

  • b既可以从l处转移又可以从r处转移:只需要判断a能不能转移到lr即可。不能ans=1

  • b既可以从l处转移:只需要判断a能不能转移到l即可。如果无法转移到l,判断a能不能转移到r,再从r转移到l。以上都不能时ans=1

  • b既可以从r处转移:同理

  • 均不能转移:ans=1

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define cerr(x) std::cerr << (#x) << " is " << (x) << '\n'
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
#define PII pair<int, int>
#define pdd pair<double,double>
#define PLL pair<LL,LL>

#define LL long long

const double CLOCKS_PER_SECOND = ((clock_t) 1000);
const double CLOCKS_PER_MILLISECOND = ((clock_t) 1);
const int N = 2e5 + 10, M = 1e8, mod = 1e9 + 7, inf = 0x3f3f3f3f;
const double eps = 1e-6;
//#define x first
//#define y second

int T;
int l, r, x;
int a, b;

void solve() {

    cin >> l >> r >> x;
    cin >> a >> b;
    if (a == b) {
        cout << 0 << endl;
        return;
    }
    if (abs(a - b) >= x) {
        cout << 1 << endl;
        return;
    }
    if (r - b >= x && b - l >= x) {
        if (r - a >= x || a - l >= x) {
            cout << 2 << endl;
            return;
        }
        cout << -1 << endl;
        return;
    }
    if (r - b >= x) {
        if (r - a >= x) {
            cout << 2 << endl;//a->r->x
            return;
        } else if (a - l >= x) {
            cout << 3 << endl;//a->l->r->x
            return;
        }
        cout << -1 << endl;
        return;
    }
    if (b - l >= x) {
        if (a - l >= x) {
            cout << 2 << endl;
            return;
        } else if (r - a >= x) {
            cout << 3 << endl;
            return;
        }
        cout << -1 << endl;
        return;
    }
    cout << -1 << endl;
}

int main() {
    IOS;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

D.Make It Round

可以发现对0产生贡献最低的只有2510

n因数分解,看有多少25,如果cnt2>cnt5则乘以(cnt2cnt5)个5,反之相同。最后令k=10直到k10>m

怎么找到同一个答案下的最大k?令k=m/kkn,就是比m小的最大数。

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define cerr(x) std::cerr << (#x) << " is " << (x) << '\n'
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
#define PII pair<int, int>
#define pdd pair<double,double>
#define PLL pair<LL,LL>

#define LL long long

const double CLOCKS_PER_SECOND = ((clock_t) 1000);
const double CLOCKS_PER_MILLISECOND = ((clock_t) 1);
const int N = 2e5 + 10, M = 1e8, mod = 1e9 + 7, inf = 0x3f3f3f3f;
const double eps = 1e-6;
//#define x first
//#define y second

int T;

LL lowbit(LL x) {
    return x & (-x);
}

void solve() {
    LL n, m;
    cin >> n >> m;
    LL t = n;
    int cnt2 = 0, cnt5 = 0;
    while (t % 2 == 0) {
        cnt2++;
        t /= 2;
    }
    t = n;
    while (t % 5 == 0) {
        cnt5++;
        t /= 5;
    }
    LL ans = 1;
    while (cnt2 < cnt5 && ans * 2 * 1LL <= m)
        ans *= 2 * 1LL, cnt2++;
    while (cnt2 > cnt5 && ans * 5 * 1LL <= m)
        ans *= 5 * 1LL, cnt5++;
    while (ans * 10 <= m) ans *= 10 * 1LL;
    cout << m / ans * ans * n << endl;
}

int main() {
    IOS;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

E.The Humanoid

暴力dp枚举喝药次数

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define cerr(x) std::cerr << (#x) << " is " << (x) << '\n'
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
#define PII pair<int, int>
#define pdd pair<double,double>
#define PLL pair<LL,LL>
#define int long long
//#define LL long long

const double CLOCKS_PER_SECOND = ((clock_t) 1000);
const double CLOCKS_PER_MILLISECOND = ((clock_t) 1);
const int N = 2e5 + 10, M = 1e8, mod = 1e9 + 7, inf = 0x3f3f3f3f;
const double eps = 1e-6;
//#define x first
//#define y second

int T;
int dp[N][5][5];
int n, t, a[N];

void solve() {
    int ans = 0;
    cin >> n >> t;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= 2; j++)
            for (int k = 0; k <= 1; k++) dp[i][j][k] = 0;
    dp[0][0][0] = t;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= 2; j++)
            for (int k = 0; k <= 1; k++) {
                int num1 = 1;
                for (int j1 = 0; j1 <= j; j1++) {
                    if (j1) num1 *= 2;
                    int num2 = 1;
                    for (int k1 = 0; k1 <= k; k1++) {
                        if (k1) num2 *= 3;
                        dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - j1][k - k1] * num1 * num2);
                    }
                }
                if (dp[i][j][k] > a[i]) {
                    dp[i][j][k] += a[i] / 2;
                    ans = max(ans, i);
                }
            }
    cout << ans << endl;
    return;
}

signed main() {
    IOS;
    cin >> T;
    while (T--) {
        solve();
    }
}
posted @   SxtoxA  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
12 13
点击右上角即可分享
微信分享提示