Kattis - Remainder Reminder

本文介绍了如何利用中国剩余定理(CRT)解决编程竞赛中的一道题目,虽然该问题可以通过暴力搜索得出答案,但在面对更复杂的情况时,了解并应用CRT显得更为重要。作者通过AC代码展示了求解过程,并表达了对掌握高级算法的必要性的认识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题链接:

https://vjudge.net/problem/Kattis-remainderreminder
https://open.kattis.com/problems/remainderreminder

AC代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
const int INF = 0x3fffffff;
typedef long long ll;
typedef unsigned long long ull;

void __init__()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
}
int a, b, c, d, e, f, g;
vector<int> siz;
int main()
{
    __init__();
    cin >> a >> b >> c >> d >> e >> f >> g;
    for (int i = 1; i * 2 < a; i++)
    {
        siz.push_back((a - i * 2) * (b - i * 2) * i);
    }
    sort(siz.begin(), siz.end());
    int v1 = siz[siz.size() - 1];
    int v2 = siz[siz.size() - 2];
    int v3 = siz[siz.size() - 3];
    for (int i = 0; i <= g / v1; i++)
    {
        ll ans = i * v1 + c;
        if (ans < f)
        {
            continue;
        }

        if (ans % v2 == d && ans % v3 == e)
        {
            cout << ans << endl;
            break;
        }
    }

    return 0;
}

看了赛后题解说是用CRT(中国剩余定理),好像确实是典型的拓展CRT模板题,但就这道题来说,不用CRT也能做,暴就完了(doge

不过既然遇到了CRT的题了还是好好学学吧,但凡时间上要求的严一点暴就过不去了Orz

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值