P10839 梦熊周赛【MX-J2-T0】Turtle and Equations

· · 题解

这是一道简简单单的枚举题

非常简单啊好吧

看一下我代码

#include<bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    for(int i=0;i<4;i++)
    {
        for(int j=0;j<4;j++)
        {
            int ans=0;
            if(i==0)
            {
                ans=a+b;
            }else if(i==1)
            {
                ans=a-b;
            }else if(i==2)
            {
                ans=a*b;
            }else if(i==3)
            {
                ans=a/b;
            }
            if(j==0)
            {
                ans+=c;
            }else if(j==1)
            {
                ans-=c;
            }else if(j==2)
            {
                ans*=c;
            }else if(j==3)
            {
                ans/=c;
            }
            if(ans==d)
            {
                cout<<"Yes";
                return 0; 
            }
        }
    }
    cout<<"No";
    return 0; 
}

非常长,但比较好理解

纯枚举