7 solutions

  • 2
    @ 2024-11-24 21:28:52

    luogu-B3863题解

    主要题意

    如果2*x(即 22 元一只的签字笔);5*x(即 55 元一本的记事本);3*z(即 33 元一把的直尺)加起来的价格多于他手里的 nn 元,那么输出No以及他缺少的钱(即s-n),否则输出Yes以及他多余的钱(即n-s)。

    解题思路

    不多说了,题意里面大都讲了。

    上代码!

    #include <bits/stdc++.h> 
    using namespace std;
    long long x,y,z,n,s=0;
    int main()
    {
    	cin>>x>>y>>z>>n;
    	s+=x*2+y*5+z*3;
    	if(s>n)
    		cout<<"No\n",cout<<s-n;
    	else
    		cout<<"Yes\n",cout<<n-s;
    }
    
    
    • 2
      @ 2024-10-24 21:25:04
      #include<iostream>
      using namespace std;
      int main() {
      	int x,y,z,q,sum = 0;
      	cin >> x >> y >> z >> q;
      	sum = x * 2 + 5 * y + z * 3;
      	if (q >= sum) cout << "Yes" << endl << q - sum << endl;
      	else cout << "No" << endl << sum - q << endl;
      	return 0;
      }
      
      • 1
        @ 2025-5-17 10:08:09

        这题的价钱都是固定的,可以把固定的单价赋值在a、b、c,再用cnt来存储总价,再分类讨论就行了

        无注释AC代码:

        #include<bits/stdc++.h>
        using namespace std;
        long long x,y,z;
        long long n;
        long long a = 2, b = 5, c = 3;
        long long cnt;
        bool flag;
        int main(){
        	cin >> x >> y >> z;
        	cin >> n;
        	cnt += x * a;
        	cnt += y * b;
        	cnt += z * c;
        	if(cnt > n){
        		flag = false;
        	}else{
        		flag = true;
        	}
        	if(flag){
        		cout << "Yes" << endl;
        		cout << n - cnt << endl;
        		return 0;
        	}else{
        		cout << "No" << endl;
        		cout << cnt - n << endl;
        		return 0;
        	} 
        	return 0;
        } 
        
        
        • 0
          @ 2025-4-22 17:42:08

          注释都在代码里

          #include<bits/stdc++.h>
          using namespace std;
          int n,m,x,y;
          int main()
          {
          	cin>>n>>m>>x>>y;
          	//这是够的情况 
          	if(n*2+m*5+x*3<=y){
          		cout<<"Yes\n";
          		cout<<y-(n*2+m*5+x*3);
          		return 0;
          	}
          	//否测是不够的情况 
          	else{
          		cout<<"No\n";
          		cout<<(n*2+m*5+x*3)-y;
          	}
          }
          
          • -1
            @ 2024-12-20 11:05:38

            #include using namespace std; int main() { int x,y,z,q,sum = 0; cin >> x >> y >> z >> q; sum = x * 2 + 5 * y + z * 3; if (q >= sum) cout << "Yes" << endl << q - sum << endl; else cout << "No" << endl << sum - q << endl; return 0; }

            • -1
              @ 2024-12-20 11:05:31

              #include using namespace std; int main() { int x,y,z,q,sum = 0; cin >> x >> y >> z >> q; sum = x * 2 + 5 * y + z * 3; if (q >= sum) cout << "Yes" << endl << q - sum << endl; else cout << "No" << endl << sum - q << endl; return 0; }

              • -1
                @ 2024-12-17 17:42:39

                #include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d,e; cin>>a>>b>>c>>d; e=2a+5b+3*c; if (d>=e) {cout<<"Yes"<<endl; d=d-e; cout<<d;} else if (d<e) {cout<<"No"<<endl; d=e-d; cout<<d;} return 0; }

                • 1

                Information

                ID
                4879
                Time
                1000ms
                Memory
                128MiB
                Difficulty
                1
                Tags
                # Submissions
                274
                Accepted
                81
                Uploaded By