【Henu ACM Round #13 C】 Ebony and Ivory

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


先求出c-bx的所有可能
->存在map里面
然后枚举y看看a
y在不在map里面
在的话就有解。
这样复杂度是\(O(N*log_2N)\)
比直接两层循环枚举的\(O(N^2)\)复杂度要来的好
这种方法也叫"中途相遇法"

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll a,b,c;
map<int,int> dic;

int main(){
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> a >> b >> c;
    for (int i = 0;i <= 10000;i++){
        if (c-b*i<0) break;
        dic[c-b*i]=1;
    }
    for (int i = 0;i <= 10000;i++)
        if (dic[a*i]){
            cout <<"Yes"<<endl;
            return 0;
        }
    cout <<"No"<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值