2 solutions

  • 0
    @ 2025-12-18 13:20:24

    100pts

    通过二分找到符合要求的最大值

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    LL n,m,a,b;
    bool check(LL k)
    {
    	double d=b-a;
    	double low=b*k-n;
    	double high=m-a*k;
    	low=ceil(low/d); //下边界
    	high=floor(high/d); //上边界
    	low=max(low,0.0),high=min(high,k*1.0);
    	return low<=high; //是否符合要求
    }
    int main()
    {
    	cin>>n>>m>>a>>b;
    	if(a==b) cout<<min(n,m)/a<<endl;
    	else{
    		if(a>b)
    		{
    			swap(a,b);
    			swap(n,m);
    		}
    		LL l=0,r=n; //左右边界
    		while(l<r)
    		{
    			int mid=l+r+1>>1;
    			if(check(mid)) l=mid;
    			else r=mid-1;
    		}
    		cout<<r;
    	}
    	return 0;
    }
    
    • 0
      @ 2025-12-18 11:38:38

      (60pts)

      通过枚举不同的组合去更新奖品数量

      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n,m,a,b;
          cin>>n>>m>>a>>b;
          int res=0;
          for(int x=0;x<=n;x++) //第一种方案
          {
              for(int y=0;y<=m;y++) //第二种方案
              {
                  int s1=a*x+y*b,s2=a*y+b*x;
                  if(s1>n) break; //超过了课堂优秀券
                  if(s2>m) break; //超过了作业优秀券
                  res=max(res,x+y);
              }
          }
          cout<<res;
          return 0;
      }
      
      • 1

      Information

      ID
      2811
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      10
      Tags
      # Submissions
      3
      Accepted
      1
      Uploaded By