题解:P15086 [UOI 2025 II Stage] A+B=C

· · 题解

枚举 0 \le i\le c,计 count(i) 为摆出数字 i 所需的火柴数。若 count(i)+count(c-i)=count(a)+count(b) 则输出 Yes 并结束程序。

如果最后也没有找到答案,输出 No 即可。

#include <bits/stdc++.h>
#define int long long
using namespace std;
int a,b,c,cnt[]={6,2,5,5,4,5,6,3,7,6};

signed main()
{
    cin>>a>>b>>c;
    for(int i=0;i<=c;i++)
    {
        if((cnt[i]+cnt[c-i])==(cnt[a]+cnt[b]))
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No";
}