招行算法第二题

解题思路:贪心算法

首先取(一等奖最大值)和(n-二等奖最小值- 二等奖最小值)中的小值

再取(二等奖最大值)和(剩余值- 二等奖最小值)中的小值

最后 三等奖的个数为剩余数量

#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	cin>>n;
	int minvalue,maxvalue;
	int num[3][2];
	int res[3]={0};
	for(int i =0;i<3;i++)
	{
		cin>>minvalue>>maxvalue;
		num[i][0] = minvalue;
		num[i][1] = maxvalue;
	}
	res[0]=min(num[0][1],n-num[1][0]-num[2][0]);
	n = n-res[0];
	res[1]=min(num[1][1],n-num[2][0]);
	res[2]=n-res[1];
	for(int i =0;i<3;i++)
	{
		cout<<res[i]<<endl;
	}
	return 0;
}

 

相关文章:

  • 2022-01-23
  • 2022-01-21
  • 2021-09-26
  • 2022-01-06
  • 2022-12-23
  • 2021-09-13
  • 2022-01-25
  • 2021-08-28
猜你喜欢
  • 2021-09-22
  • 2021-04-09
  • 2021-08-12
  • 2021-05-16
  • 2021-12-16
  • 2022-12-23
  • 2022-01-17
相关资源
相似解决方案